home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / pc_board / ansi_i.zip / ANSI.ASM next >
Assembly Source File  |  1992-01-01  |  116KB  |  2,114 lines

  1. ;------------------------------------------------------------------------;
  2. ;  ANSI.COM - Replacement for the ANSI.SYS console device driver.        ;
  3. ;  Unlike ANSI.SYS which must be installed at boot time, ANSI.COM        ;
  4. ;  can be installed and uninstalled at anytime.  Enhancements include    ;
  5. ;  a fast screen write and variable sized keyboard reassignment buffer.  ;
  6. ;                                                                        ;
  7. ;  Update 3/2/89 - Fix for DOS function 0Bh, Check Standard Input Status ;
  8. ;                      and STDIN in ANSI_INT_21 handler.                 ;
  9. ;                  Leading zero inserted for Device Status Report for    ;
  10. ;                      single digit cursor positions.                    ;
  11. ;                  INFORMATION typo 40 for 40H.                          ;
  12. ;                  WRITE_FAST modified to handle CR and LF instead of    ;
  13. ;                      WRITE_CHAR.                                       ;
  14. ;  Update 3/7/89 - Fix for CLS in graphics mode.          Version 1.2    ;
  15. ;                                                                        ;
  16. ;  Update 8/8/89 - STI added to INT 21 and 29 handler.    Version 1.3    ;
  17. ;:                                                                       ;
  18. ;: Update 01/01/90 - [KON | KOFF] and [PON | POFF] added  Version 1.31   ;
  19. ;:                   (all changes marked with ;: - Gary Meeker)          ;
  20. ;| Update 03/23/90 - /Q option added for no output when exectued  1.32   ;
  21. ;|                   (all changes marked with ;| - Gary Meeker)          ;
  22. ;; Update 05/16/90 - removed Syntax from output unless needed     1.33   ;
  23. ;;                   added /T test for load.                             ;
  24. ;;                   (all changes marked with ;; - Gary Meeker)          ;
  25. ;. Update 10/28/90 - Added /P nn top of screen protection mode    1.34   ;
  26. ;.                   (all changes marked with ;. - Gary Meeker)          ;
  27. ;@ Update 12/01/90 - Added PCBoard @X## color code support        1.35   ;
  28. ;@                   also added @Variable@ Support                       ;
  29. ;@                   added /S to load stats data from file               ;
  30. ;@                   (all changes marked with ;@ - Gary Meeker)          ;
  31. ;&                                                                       ;
  32. ;& Update 12/12/90 - My mistake, I didn't realize @X00 saved      1.36   ;
  33. ;&                   the color and @XFF restored it. Works now.          ;
  34. ;&                   Also made prompts return to start of line           ;
  35. ;&                   when cleared (like PCBoard does) & QON              ;
  36. ;&                   now changes @MORE@ & @PAUSE@ into @WAIT@            ;
  37. ;&                   (all changes marked with ;& - Gary Meeker)          ;
  38. ;                                                                        ;
  39. ;$ Update  4/22/91 - Change set cursor routine. If new position   1.37   ;
  40. ;$                   is off the screen use the last row or column.       ;
  41. ;$                   Added switch to not include PCB code.               ;
  42. ;$                   Corrected syntax display.                           ;
  43. ;$                   Modified CLS to honor protected (/P) lines.         ;
  44. ;$                   Modified /T to returned status switches.            ;
  45. ;$                   Modified /P to accept * to mean current row-1.      ;
  46. ;$                   (all changes marked with ;$ - Wayne Mingee)         ;
  47. ;                                                                        ;
  48. ;+ Update  9/19/91 - Allow ESC[p to clear all KB reassigns and    1.38   ;
  49. ;+                   ESC[np to clear single key reassign.                ;
  50. ;+                   ie: ESC[65p will reset ascii 65 to it's default [A] ;
  51. ;                                                                        ;
  52. ;^ Update 01/01/92 - Added XON/XOFF to control @X## color codes   1.39   ;
  53. ;^                   added support for finding relocated copies.         ;
  54. ;^                   This should allow LOADHI under DOS 5 or QRAM/QEMM   ;
  55. ;^                   (all changes marked with ;^ - Gary Meeker)          ;
  56. ;^                   (Was added to my 1.37 version 01/09/91 but now      ;
  57. ;^                   incorporated into this version as 1.39 to include   ;
  58. ;^                   changes by Wayne Mingee)                            ;
  59. ;                                                                        ;
  60. ;  PC Magazine - Michael J. Mefford                                      ;
  61. ;------------------------------------------------------------------------;
  62.  
  63. PCB            equ     1                     ;$ 1 = if PCB code wanted
  64.  
  65. _TEXT          SEGMENT PUBLIC 'CODE'
  66.                ASSUME  CS:_TEXT,DS:_TEXT,ES:_TEXT,SS:_TEXT
  67.                ORG     100H
  68. START:         JMP     INITIALIZE
  69.  
  70. ;                 DATA AREA
  71. SIGNATURE      DB      CR,SPACE,SPACE,SPACE,CR,LF
  72. COPYRIGHT      DB      "ANSI 1.3i (C) 1988 Ziff Communications Co.",CR,LF    ;^
  73. PROGRAMMER     DB      "PC Magazine ",BOX," Michael J. Mefford",CR,LF,LF,"$"
  74.                DB      CTRL_Z
  75.  
  76. CR             EQU     13
  77. LF             EQU     10
  78. CTRL_Z         EQU     26
  79. SPACE          EQU     32
  80. BOX            EQU     254
  81. ESC_CHAR       EQU     27
  82. SINGLE_QUOTE   EQU     39
  83. DOUBLE_QUOTE   EQU     34
  84. BELL           EQU     7
  85. BS             EQU     8
  86. TAB            EQU     9
  87.  
  88. OFF            EQU     1
  89. ON             EQU     2
  90. SLOW           EQU     4
  91. FAST           EQU     8
  92. KOFF           EQU     16                         ;:
  93. KON            EQU     32                         ;:
  94. POFF           EQU     64                         ;:
  95. PON            EQU     128                        ;:
  96. XOFF           EQU     256                        ;^
  97. XON            EQU     512                        ;^
  98. STATUS_MASK    EQU     1111110000000001B          ;: Set Mask and Bit
  99. AND_MASK       EQU     1111111111111100B          ;^ Set Mask
  100. OR_MASK        EQU     0000000000000001B          ;^ Set Bit
  101.  
  102. ANSI_STATE     DW      ESC_STATE
  103. STATUS         DW      ON OR FAST OR KON OR PON OR XON    ;: ;^
  104. PARAMETERS     DB      "OFF",0,"ON",0,0,"SLOWFASTKOFFKON",0,"POFFPON",0 ;:
  105.                DB      "XOFFXON",0                                      ;^
  106. LAST_PARAMETER EQU     $ - PARAMETERS
  107.  
  108. multiplex_id   db      0dbh                    ;^ Program ID for multiplex int
  109. dos_version    dw      0                       ;^ DOS Version number
  110. int2fh         dd      -1                      ;^ Int 2f vector (DOS MULTIPLEX)
  111. OLD_INT_29     DW      ?,?
  112. OLD_INT_16     DW      ?,?
  113. OLD_INT_21     DW      ?,?
  114. if PCB                                            ;$
  115. OLD_INT_08     DW      ?,?              ;@ Save Timer Interupt
  116. endif                                             ;$
  117. ATTRIBUTE      DB      7
  118. if PCB                                            ;$
  119. SAVE_ATTRIBUTE DB      ?                ;& For saving attribute
  120. endif                                             ;$
  121. SAVE_POSITION  DW      0
  122. LINE_WRAP      DB      ON
  123. QUOTE_TYPE     DB      ?
  124. ESC_COUNT      DW      0
  125. NUMBER_COUNT   DW      0
  126.  
  127. COMMAND_TABLE  LABEL   BYTE
  128. DB   "H", "A", "B", "C", "D", "f", "n", "s", "u", "K", "m", "h", "l", "p", "J"
  129. COMMAND_LENGTH EQU     $ - COMMAND_TABLE
  130.  
  131. DW   CURS_POSITION, CURSOR_UP,     CURSOR_DOWN, CURS_FORWARD, CURS_BACKWARD
  132. DW   HORZ_VERT_POS, DEVICE_STATUS, SAVE_CURSOR, RESTORE_CURS, ERASE_IN_LINE
  133. DW   SGR,           SET_MODE,      RESET_MODE,  REASSIGNMENT, CLS
  134. COMMAND_END    EQU     $ - 2
  135.  
  136. ATTRIBUTE_TABLE        LABEL    BYTE
  137. DB   00,01,04,05,07,08,30,31,32,33,34,35,36,37,40,41,42,43,44,45,46,47
  138. ATTRIBUTE_LENGTH       EQU      $ - ATTRIBUTE_TABLE
  139.  
  140. ;Format: AND mask,OR mask
  141. DB      000H,07H, 0FFH,08H, 0F8H,01H, 0FFH,80H, 0F8H,70H, 088H,00H
  142. DB      0F8H,00H, 0F8H,04H, 0F8H,02H, 0F8H,06H, 0F8H,01H, 0F8H,05H
  143. DB      0F8H,03H, 0F8H,07H, 08FH,00H, 08FH,40H, 08FH,20H, 08FH,60H
  144. DB      08FH,10H, 08FH,50H, 08FH,30H, 08FH,70H
  145. ATTRIBUTE_END          EQU      $ - 2
  146.  
  147. if PCB                                            ;$
  148. AT_VARIABLE_TABLE      LABEL BYTE                                          ;@
  149. DB   '@CLS@CLREOL@AUTOMORE@POFF@PON@QOFF@QON@BEEP@MORE@PAUSE@WAIT@HANGUP@' ;@
  150. DB   'OPTEXT@FIRSTU@FIRST@USER@CITY@HOMEPHONE@DATAPHONE@PROLTR@PRODESC@'   ;@
  151. DB   'EXPDATE@LASTDATEON@LASTTIMEON@INCONF@CONFNAME@BOARDNAME@'            ;@
  152. DB   'LASTCALLERNODE@LASTCALLERSYSTEM@EVENT@SYSOPIN@SYSOPOUT@BPS@NODE@'    ;@
  153. DB   'SYSDATE@SYSTIME@FILERATIO@BYTERATIO@'                                ;@
  154. DB   'SECURITY@NUMCALLS@NUMTIMESON@TIMELEFT@TIMELIMIT@TIMEUSED@TOTALTIME@' ;@
  155. DB   'BYTESLEFT@BYTELIMIT@DLFILES@UPFILES@KBLEFT@KBLIMIT@CONFNUM@'         ;@
  156. DB   'CURMSGNUM@HIGHMSGNUM@LOWMSGNUM@MSGREAD@MSGLEFT@NUMBLT@NUMDIR@'       ;@
  157. DB   'DAYBYTES@MINLEFT@DLBYTES@UPBYTES@EXPDAYS@'                           ;@
  158.  
  159. LAST_VARIABLE          EQU     $ - 1                                       ;@
  160.  
  161. JUMP_TABLE             LABEL WORD                                          ;@
  162. DW      CLS, ERASE_IN_LINE, AUTOMORE, AUTOOFF, AUTOOFF, QOFF, QON        ;&;@
  163. DW      BEEP, MORE, PAUSE, WAIT1, SKIP_IT                                  ;@
  164.  
  165. SUB_TABLE              LABEL BYTE                                          ;@
  166. DB      8,15,15,25,24,13,13,1,47                                           ;@
  167. DB      8,8,5,33,13,63                                                     ;@
  168. DB      52,52,5,5,5,5,2                                                    ;@
  169. DB      0,0,4,4                                                            ;@
  170. DB      2,4,2,2,2,2,2                                                      ;@
  171. DB      4,4,2,2,4,4,2                                                      ;@
  172. DB      4,4,4,4,4,2,2                                                      ;@
  173. DB      4,2,4,4,2                                                          ;@
  174.  
  175. SUB_LIST               LABEL BYTE                      ;@
  176. DB     '!OPTEXT!'                                      ;@ OPTTEXT
  177. DB     'GARY',0,0,0,0,0,0,0,0,0,0,0                    ;@ FirstU
  178. DB     'Gary',0,0,0,0,0,0,0,0,0,0,0                    ;@ First
  179. DB     'GARY MEEKER',0,0,0,0,0,0,0,0,0,0,0,0,0,0       ;@ User
  180. DB     'LAWRENCEVILLE, GA',0,0,0,0,0,0,0               ;@ City
  181. DB     '404 995-2699',0                                ;@ HomePhone
  182. DB     '404 962-1788',0                                ;@ DataPhone
  183. DB     'Z'                                             ;@ Proltr
  184. DB     'Zmodem       (Batch U/L and D/L)', 15 DUP (0)  ;@ ProDesc
  185. DB     '01-01-91'                                      ;@ ExpDate
  186. DB     '12-01-90'                                      ;@ LastDateOn
  187. DB     '08:00'                                         ;@ LastTimeOn
  188. DB     'Magazine (1) Conference ',0,0,0,0,0,0,0,0,0    ;@ InConf
  189. DB     'Magazine',0,0,0,0,0                            ;@ ConfName
  190. DB     'SHARP Technical Support Line BBS', 31 DUP (0)  ;@ BoardName
  191. DB     'MIKE BATE (RIVERDALE, GA)', 27 DUP (0)         ;@ LastCallerNode
  192. DB     'GARY MEEKER (LAWRENCEVILLE, GA)', 21 DUP (0)   ;@ LastCallerSystem
  193. DB     '04:30'                                         ;@ Event
  194. DB     '08:30'                                         ;@ SysopIn
  195. DB     '17:00'                                         ;@ SysopOut
  196. DB     '2400',0                                        ;@ bps
  197. DB     '1',0                                           ;@ Node
  198.  
  199. DD     48                                              ;@ FileRatio
  200. DD     128                                             ;@ ByteRatio
  201.  
  202. DW         120                                         ;@ Security
  203. DD       23946                                         ;@ numcalls
  204. DW        2107                                         ;@ numtimeson
  205. DW          61                                         ;@ timeleft
  206. DW         121                                         ;@ timelimit
  207. DW          59                                         ;@ timeused
  208. DW          59                                         ;@ totaltime
  209. DD     9508313                                         ;@ bytesleft
  210. DD    10238976                                         ;@ bytelimit
  211. DW          44                                         ;@ dlfiles
  212. DW        1234                                         ;@ upfiles
  213. DD        9285                                         ;@ KBLeft
  214. DD        9999                                         ;@ KBLimit
  215. DW           1                                         ;@ ConfNum
  216. DD        4734                                         ;@ CurMsgNum
  217. DD        4745                                         ;@ HighMsgNum
  218. DD           2                                         ;@ LowMsgNum
  219. DD        3456                                         ;@ MsgRead
  220. DD         987                                         ;@ MsgLeft
  221. DW          20                                         ;@ NumBlt
  222. DW          31                                         ;@ NumDir
  223. DD       30663                                         ;@ DayBytes
  224. DW          61                                         ;@ MinLeft
  225. DD      730663                                         ;@ DLBytes
  226. DD    12345678                                         ;@ UpBytes
  227. DW           0                                         ;@ ExpDays
  228. SUB_LENGTH     EQU      $ - SUB_LIST
  229.  
  230. PAUSE_TIMER    DW      182                             ;@
  231. PAUSE_DELAY    DW      182                             ;@ 10 Seconds
  232. MORE_DELAY     DW      182 * 12                        ;@ 2 Minute
  233. WAIT_DELAY     DW      182 * 12                        ;@ 2 Minute
  234.  
  235. WAIT_PROMPT    DB      'press enter to continue'       ;@
  236. WAIT_LENGTH    DW      $ - WAIT_PROMPT                 ;@
  237. MORE_PROMPT    DB      '(61 min left), (H)elp, More?'  ;@
  238. MORE_LENGTH    DW      $ - MORE_PROMPT                 ;@
  239. COMMA          DB      0                               ;@
  240. Q_STATE        DB      0                               ;&
  241. endif                                             ;$
  242.  
  243. BIOS_ACTIVE_PAGE       EQU     62H
  244. ACTIVE_PAGE    DB      ?
  245. ADDR_6845      DW      ?
  246. BIOS_CRT_MODE          EQU     49H
  247. CRT_MODE       DB      ?
  248. CRT_COLS       DW      ?
  249. CRT_LEN        DW      ?
  250. CRT_START      DW      ?
  251. CRT_DATA_LENGTH        EQU     $ - CRT_MODE
  252. CURSOR_POSN    LABEL   WORD
  253. CURSOR_COL     DB      ?
  254. CURSOR_ROW     DB      ?
  255. CRT_ROWS       DB      ?
  256.  
  257. START_SCROLL   DB      0       ;. Number of rows to protect from scrolling up
  258.  
  259. DOS_INPUT      DB      OFF
  260. BUSY_FLAG      DB      OFF
  261. REASSIGN_FLAG  DB      OFF
  262. REMOVE_FLAG    DB      ON
  263. REASSIGN_COUNT DW      0
  264. REASSIGN_POS   DW      ?
  265. FUNCTION_16    DB      ?
  266. ZR             EQU     1000000B
  267.  
  268. ESC_BUFFER_SIZE      EQU     126
  269. REASSIGNMENT_DEFAULT EQU     200
  270. REASSIGNMENT_SIZE    DW      REASSIGNMENT_DEFAULT
  271. REASSIGNMENT_MAX     EQU     60 * 1024
  272. REASSIGN_END         DW      REASSIGNMENT_BUFFER
  273. BUFFER_END           DW      REASSIGNMENT_BUFFER + REASSIGNMENT_DEFAULT
  274.  
  275. ;                   CODE AREA
  276. ;************* INTERRUPT HANDLERS *************;
  277. ;------------------------------------------------------------------------------;
  278. ; INT 29 is an undocumented interrupt called by DOS for output to the console. ;
  279. ;------------------------------------------------------------------------------;
  280.  
  281. ANSI_INT_29    PROC    FAR
  282.                STI
  283.                PUSH    AX                      ;Save all registers.
  284.                PUSH    BX
  285.                PUSH    CX
  286.                PUSH    DX
  287.                PUSH    SI
  288.                PUSH    DI
  289.                PUSH    DS
  290.                PUSH    ES
  291.                PUSH    BP
  292.  
  293.                CLD                             ;All string operations forward.
  294.                MOV     BX,CS                   ;Point to our data segment.
  295.                MOV     DS,BX
  296.                MOV     ES,BX
  297.                CALL    ANSI_STATE              ;Call the current state of
  298.                                                ; the ANSI Esc sequence.
  299.                POP     BP
  300.                POP     ES
  301.                POP     DS
  302.                POP     DI
  303.                POP     SI
  304.                POP     DX
  305.                POP     CX
  306.                POP     BX
  307.                POP     AX                      ;Restore all registers and
  308.                IRET                            ; and return
  309. ANSI_INT_29    ENDP
  310.  
  311. ;------------------------------------------------;
  312.  
  313. ANSI_INT_21    PROC    FAR
  314.                PUSHF
  315.                CMP     AH,0BH                  ;If DOS function 0Bh (Check
  316.                JNZ     CK_INPUT                ; Standard Input Status)
  317.                CMP     CS:REASSIGN_FLAG,ON     ; and reassignment in progress,
  318.                JNZ     CK_INPUT                ; including a Device Status
  319.                CALL    DWORD PTR CS:OLD_INT_21 ; Request, then process call in
  320.                MOV     AL,0FFH                 ; case control break pressed;
  321.                IRET                            ; then return 0FFh for char ready
  322.  
  323. CK_INPUT:      CMP     AH,3FH                  ;Read from STDIN?
  324.                JNZ     CK_CONSOLE
  325.                OR      BX,BX
  326.                JZ      INPUT
  327.  
  328. CK_CONSOLE:    CMP     AH,0AH                  ;If DOS Int 21 functions Ah,
  329.                JZ      INPUT                   ; 7h, 1h or console input (6h)
  330.                CMP     AH,7                    ; then tell INT 16, DOS input
  331.                JZ      INPUT                   ; is active.
  332.                CMP     AH,1
  333.                JZ      INPUT
  334.                CMP     AH,8
  335.                JZ      INPUT
  336.                CMP     AH,6
  337.                JNZ     QUICK21_EXIT
  338.                CMP     DL,0FFH
  339.                JZ      INPUT
  340. QUICK21_EXIT:  POPF                              ;If not, let the original
  341.                JMP     DWORD PTR CS:OLD_INT_21   ; interrupt process the call.
  342.  
  343. INPUT:         POPF
  344.                MOV     CS:DOS_INPUT,ON           ;INT 16 handler flag.
  345.                PUSHF
  346.                CALL    DWORD PTR CS:OLD_INT_21   ;Emulate an interrupt.
  347.                MOV     CS:DOS_INPUT,OFF          ;Turn flag back off.
  348.                STI
  349.                RET     2                         ;Return with current flags.
  350. ANSI_INT_21    ENDP
  351.  
  352. ;-----------------------------------------------------------------;
  353. ; If we get here via a DOS console input call, any awaiting key   ;
  354. ; in keyboard buffer is checked to see if it is to be reassigned. :
  355. ;-----------------------------------------------------------------;
  356.  
  357. ANSI_INT_16    PROC    FAR
  358.                STI                             ;Interrupts back on.
  359.                PUSHF                           ;Preserve flags on stack.
  360.                PUSH    BP
  361.                PUSH    DS
  362.                PUSH    AX
  363.                PUSH    CS                      ;Point to our data.
  364.                POP     DS
  365.  
  366.                CMP     DOS_INPUT,OFF           ;If not called via a DOS
  367.                JZ      QUICK16_EXIT            ; console input call, exit.
  368.                CMP     BUSY_FLAG,ON            ;If already processing a call,
  369.                JZ      QUICK16_EXIT            ; exit.
  370.                CLD                             ;All string operations forward.
  371.                MOV     BP,SP                   ;Base reference to flags on stack
  372.                MOV     FUNCTION_16,AH          ;Save function request.
  373.                AND     AH,NOT 10H              ;Strip possible extended request.
  374.                JZ      GET_KEY                 ;If zero, it's wait for a key.
  375.                DEC     AH                      ;Else, decrement.  If zero it's
  376.                JZ      KEY_STATUS              ; key status, else exit.
  377.  
  378. QUICK16_EXIT:  POP     AX                      ;Restore registers and let
  379.                POP     DS                      ; original interrupt handler
  380.                POP     BP                      ; process the call.
  381.                POPF
  382.                JMP     DWORD PTR CS:OLD_INT_16
  383.  
  384. KEY_STATUS:    OR      BYTE PTR [BP+6],ZR      ;Assume none ready; ZR = 1.
  385. GET_KEY:       MOV     BUSY_FLAG,ON            ;Non-reentrant; flag busy.
  386.                POP     AX
  387.                PUSH    BX                      ;Save some more registers.
  388.                PUSH    CX
  389.                PUSH    DX
  390.                PUSH    SI
  391.                PUSH    DI
  392.                CMP     REASSIGN_FLAG,ON        ;Already in process of reassign?
  393.                JZ      CK_BUFFER               ;If yes, check kbd buffer.
  394.  
  395.                PUSHF                           ;Else, emulate an interrupt.
  396.                CALL    DWORD PTR OLD_INT_16
  397.                PUSHF                           ;Status call results in flags.
  398.                TEST    FUNCTION_16,1           ;Was it a status call?
  399.                JZ      CK_DUP                  ;If no, check key returned.
  400.                POPF                            ;Else, retrieve status results.
  401.                JZ      INT16_EXIT              ;If zero, no key waiting.
  402.                AND     BYTE PTR [BP+6],NOT ZR  ;Else, ZR = 0.
  403.                PUSHF                           ;PUSHF just to keep stack right.
  404.  
  405. CK_DUP:        POPF                            ;Fix stack.
  406.                TEST    STATUS,KOFF             ;:If KOFF then we don't do
  407.                JNZ     INT16_EXIT              ;:re-assignments
  408.                MOV     BX,AX                   ;Match procedure wants key in BX.
  409.                CALL    CK_MATCH                ;Check reassignment buffer.
  410.                JC      INT16_EXIT              ;If no match, exit.
  411.                MOV     AX,[DI]                 ;Else, retrieve string length.
  412.                SUB     AX,3                    ;Adjust for length word and match
  413.                ADD     DI,3                    ; byte; same for string pointer.
  414.                OR      BL,BL                   ;Extended key? ie. key = 0.
  415.                JNZ     STORE_COUNT             ;If no, save length and pointer.
  416.                DEC     AX                      ;Else, adjust for extended code.
  417.                INC     DI
  418. STORE_COUNT:   MOV     REASSIGN_COUNT,AX       ;Save string length.
  419.                MOV     REASSIGN_POS,DI         ;Save pointer to string.
  420.                MOV     REASSIGN_FLAG,ON        ;Flag that replacement in effect.
  421. CK_BUFFER:     TEST    FUNCTION_16,1           ;Was it a key wait function call?
  422.                JNZ     RETRIEVE                ;If no, key status; get it.
  423.                CMP     REMOVE_FLAG,OFF         ;Removed it from kbd buffer?
  424.                JZ      RETRIEVE                ;If yes, get reassignment.
  425.                MOV     AH,FUNCTION_16          ;Else, eat the replaced character
  426.                INT     16H                     ; via INT 16.
  427.                MOV     REMOVE_FLAG,OFF         ;Flag character eaten.
  428.  
  429. RETRIEVE:      MOV     DI,REASSIGN_POS         ;Retrieve pointer to string.
  430.                MOV     AX,[DI]                 ;Retrieve replacement character.
  431.                TEST    FUNCTION_16,1           ;Is it a key wait function call?
  432.                JZ      REMOVE                  ;If yes, bump pointer up one.
  433.                AND     BYTE PTR [BP+6],NOT ZR  ;If no, status call; ZR = 0
  434.                JMP     SHORT INT16_EXIT        ;All done.
  435.  
  436. REMOVE:        INC     REASSIGN_POS            ;Move pointer to next character.
  437.                DEC     REASSIGN_COUNT          ;One less character to replace.
  438.                JZ      REASSIGN_DONE           ;If end of string, reset flags.
  439.                OR      AL,AL                   ;Else, extended replacement?
  440.                JNZ     INT16_EXIT              ;If no, done here.
  441.                INC     REASSIGN_POS            ;Else adjust pointers.
  442.                DEC     REASSIGN_COUNT
  443.                JNZ     INT16_EXIT              ;End of string?
  444. REASSIGN_DONE: MOV     REASSIGN_FLAG,OFF       ;If yes, reset flags.
  445.                MOV     REMOVE_FLAG,ON
  446.  
  447. INT16_EXIT:    MOV     BUSY_FLAG,OFF           ;Reset the busy flag.
  448.                POP     DI                      ;Restore registers.
  449.                POP     SI
  450.                POP     DX
  451.                POP     CX
  452.                POP     BX
  453.                POP     DS
  454.                POP     BP
  455.                POPF                            ;Flags on stack have status
  456.                RET     2                       ; results; kill old flags.
  457. ANSI_INT_16    ENDP
  458. if PCB                                            ;$
  459. ANSI_INT_08    PROC    FAR                      ;@
  460.                CMP     CS:[PAUSE_TIMER],0       ;@
  461.                JE      SKIP_TIMER               ;@
  462.                DEC     CS:[PAUSE_TIMER]         ;@
  463. SKIP_TIMER:    JMP     DWORD PTR CS:OLD_INT_08  ;@
  464. ANSI_INT_08    ENDP                             ;@
  465. endif                                             ;$
  466. ;^============================================================================
  467. ;^ MUXINT processes calls to interrupt 2Fh
  468. ;^ Entry:  AH - Device ID
  469. ;^ Exit:   AL - 0FFh if AH = Alias device ID. Unchanged otherwise.
  470. ;^         ES - Code segment if AH = Alias device ID. Unchanged otherwise.
  471. ;^============================================================================
  472. muxint         proc    far                     ;^
  473.                cmp     ah,cs:[multiplex_id]    ;^ Check for program ID
  474.                je      muxint_1                ;^ Its us, indicate installed.
  475.                jmp     cs:[int2fh]             ;^ else pass the call on
  476. muxint_1:                                      ;^
  477.                mov     al,-1                   ;^ Indicate Alias installed
  478.                push    cs                      ;^ ES = installed code segment
  479.                pop     es                      ;^
  480.                iret                            ;^
  481. muxint         endp                            ;^
  482.  
  483. ;************* ANSI ESCAPE STATE ROUTINES ************* ;
  484.  
  485. ESC_STATE:     MOV     BX,OFFSET BRACKET_STATE ;Assume Esc character.
  486.                CMP     AL,ESC_CHAR             ;Is it Esc?  If yes, store
  487.                JZ      SHORT_JUMP              ; char. and next state.
  488. if PCB                                            ;$
  489.                CMP     DOS_INPUT,ON            ;@ Called via DOS Input?
  490.                JE      WRITE_CHAR2             ;@ Yes, Nevermind
  491.                MOV     BX,OFFSET ATX_STATE     ;@ No, Assume @ Character
  492.                CMP     AL,"@"                  ;@ Is it @? If yes, store
  493.                JZ      SHORT_JUMP              ;@ char. and next state.
  494. WRITE_CHAR2:
  495. endif                                             ;$
  496.                JMP     WRITE_CHAR              ;@ Else, normal char; write it.
  497. ;------------------------------------------------;
  498.  
  499. BRACKET_STATE: MOV     BX,OFFSET SPECIAL_STATE ;Assume left bracket.
  500.                CMP     AL,"["                  ;Is it left bracket?  If yes,
  501. SHORT_JUMP:    JZ      STORE_STATE             ;store char. and next state.
  502.                JMP     FLUSH_BUFFER            ;Else, flush Esc out of buffer.
  503.  
  504. ;---------------------------------------------------------------;
  505. ; Must process <ESC>[2J (CLS) regardless if ANSI.COM ON or OFF. ;
  506. ;---------------------------------------------------------------;
  507.  
  508. SPECIAL_STATE: MOV     BX,OFFSET CLS_STATE     ;Assume Erase in Display code.
  509.                CMP     AL,"2"                  ;Is it the "2" ?
  510.                JZ      STORE_STATE             ;If yes, progress to next state.
  511.                TEST    STATUS,OFF              ;Else, is ANSI OFF ?
  512.                JNZ     FLUSH_BUFFER            ;If yes, flush Esc, bracket.
  513.                MOV     BX,OFFSET PARAM_STATE   ;Else, check for first Set,
  514.                CMP     AL,"="                  ; Reset Mode characters of
  515.                JZ      STORE_STATE             ; "=" and "?".
  516.                CMP     AL,"?"
  517.                JZ      STORE_STATE             ;If found, store.
  518.                JMP     SHORT DO_PARAMETER      ;Else, check other codes.
  519.  
  520. ;------------------------------------------------;
  521.  
  522. CLS_STATE:     CMP     AL,"J"                  ;Is it second character of CLS?
  523.                MOV     DI,OFFSET COMMAND_END   ;If yes, execute
  524.                JZ      EXECUTE                 ; Erase in Display procedure.
  525.                TEST    STATUS,OFF              ;ANSI OFF?  If yes, flush buffer.
  526.                JNZ     FLUSH_BUFFER            ; If not fall through to process.
  527.                MOV     BYTE PTR NUMBER_BUFFER,2   ;Store the previous 2.
  528. DO_PARAMETER:  MOV     ANSI_STATE,OFFSET PARAM_STATE  ;Parameter state.
  529.  
  530. ;------------------------------------------------;
  531.  
  532. PARAM_STATE:   CALL    CK_QUOTE                ;Is it single or double quotes?
  533.                JZ      STORE_STATE             ;If yes, store string state.
  534.                CMP     AL,";"                  ;Is it semi-colon delimiter?
  535.                JNZ     CK_NUMBER               ;If no, check if number.
  536.                INC     NUMBER_COUNT            ;Else, increment number count.
  537.                JMP     SHORT BUFFER_CHAR       ;Buffer the semi-colon.
  538.  
  539. CK_NUMBER:     CMP     AL,"0"                  ;Is it below 0 ?
  540.                JB      FLUSH_BUFFER            ;If yes, illegal; flush buffer.
  541.                CMP     AL,"9"                  ;Else, is it above 9 ?
  542.                JA      DO_COMMAND              ;If yes, check for command char.
  543.                CALL    ACCUMULATE              ;Else it's a number; accumulate.
  544.                JMP     SHORT BUFFER_CHAR       ;Buffer the character.
  545.  
  546. DO_COMMAND:    MOV     DI,OFFSET COMMAND_TABLE ;Point to legal ANSI commands.
  547.                MOV     CX,COMMAND_LENGTH       ;Number of commands.
  548.                REPNZ   SCASB                   ;Check for a match.
  549.                JNZ     FLUSH_BUFFER            ;If no match, flush sequence.
  550.                INC     NUMBER_COUNT            ;Else, increment for last number.
  551.                MOV     DI,OFFSET COMMAND_END   ;Point to appropriate command
  552.                SHL     CX,1                    ; processing procedure.
  553.                SUB     DI,CX
  554. EXECUTE:       CALL    GET_BIOS_DATA           ;Get cursor position data.
  555.                CALL    DS:[DI]                 ;Do command subroutine.
  556.                JMP     SHORT FLUSH_END         ;Clear buffer.
  557.  
  558. ;------------------------------------------------;
  559.  
  560. QUOTE_STATE:   CMP     AL,QUOTE_TYPE           ;Is it an ending string quote?
  561.                JNZ     BUFFER_CHAR             ;If no, buffer literal.
  562.                MOV     BX,OFFSET PARAM_STATE   ;Else, back to parameter parsing.
  563.  
  564. ;------------------------------------------------;
  565.  
  566. STORE_STATE:   MOV     ANSI_STATE,BX           ;Store the ANSI state.
  567.  
  568. ;------------------------------------------------;
  569.  
  570. BUFFER_CHAR:   MOV     DI,ESC_COUNT            ;Buffer the character in case
  571.                CMP     DI,ESC_BUFFER_SIZE      ; ending ANSI command is illegal.
  572.                JZ      FLUSH_BUFFER            ;If buffer full, flush.
  573.                ADD     DI,OFFSET ESC_BUFFER    ;Point to next buffer position.
  574.                STOSB                           ;Store the character.
  575.                INC     ESC_COUNT               ;Increment the sequence count.
  576.                RET
  577.  
  578. ;------------------------------------------------;
  579.  
  580. FLUSH_BUFFER:                                     ;$
  581. if PCB                                            ;$
  582.                CALL    BUFFER_CHAR             ;@ Buffer current character also!
  583. FLUSH_BUFF2:                                   ;@
  584. else                                              ;$
  585.                PUSH    AX                      ;Save the current character. Might need removal
  586. endif                                             ;$
  587.                MOV     SI,OFFSET ESC_BUFFER    ;Point to the sequence buffer.
  588.                MOV     CX,ESC_COUNT            ;Count of buffered characters.
  589. NEXT_FLUSH:    LODSB                           ;Retrieve one.
  590.                PUSH    CX                      ;Save counter and pointer.
  591.                PUSH    SI
  592.                CALL    WRITE_CHAR              ;Write character to screen.
  593.                POP     SI                      ;Restore counter and pointer.
  594.                POP     CX
  595.                LOOP    NEXT_FLUSH              ;Flush entire buffer.
  596. ife PCB                                           ;$
  597.                POP     AX                      ;@Retrieve last character.   Might need removal
  598.                CALL    WRITE_CHAR              ;@Write it also.             Might need removal
  599. endif                                             ;$
  600. FLUSH_END:     MOV     ESC_COUNT,0                   ;Reset counter.
  601.                MOV     ANSI_STATE,OFFSET ESC_STATE   ;Back to Esc state.
  602.                MOV     NUMBER_COUNT,0                ;Reset parameter counter.
  603.                PUSH    CS                            ;Point to our data.
  604.                POP     ES
  605.                MOV     DI,OFFSET NUMBER_BUFFER       ;Clear number buffer
  606.                MOV     CX,ESC_BUFFER_SIZE / 2        ; to zeros.
  607.                XOR     AX,AX
  608.                REP     STOSW
  609.                RET
  610. if PCB                                            ;$
  611. ;------------------------------------------------;@
  612. COLOR_STATE:   MOV     AH,AL                   ;^ Save character
  613.                CMP     AL,"0"                  ;@ Is it below 0 ?
  614.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  615.                CMP     AL,"9"                  ;@ Else, is it 0 - 9 ?
  616.                JBE     DO_COLOR                ;@ If yes, Make color.
  617.                CMP     AL,'A'                  ;@ Is it below A ?
  618.                JB      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  619.                CMP     AL,'F'                  ;@ Is it Above F ?
  620.                JA      FLUSH_BUFFER            ;@ If yes, illegal; flush buffer.
  621.                SUB     AL,7                    ;@ Else, adjust for Hex
  622. DO_COLOR:      CALL    ACCUM_COLOR             ;@ Accumulate Color.
  623.                MOV     AH,AL                   ;^ get saved character
  624.                INC     NUMBER_COUNT            ;@ Count the character
  625.                CMP     NUMBER_COUNT,2          ;@ Already got two?
  626. BUFFER_JUMP:   JNE     SHORT BUFFER_CHAR     ;&;@ No, Buffer the character.
  627.                TEST    STATUS,OFF              ;@ Else, is ANSI OFF ?
  628.                JNZ     FLUSH_BUFFER            ;@ If yes, flush Esc, bracket.
  629.                TEST    STATUS,XOFF             ;^ Are @Xnn colors off?
  630.                JNZ     FLUSH_END               ;^ Yes, Ignore this completely
  631.                INC     CL                      ;& Is it @XFF restore code?
  632.                JNZ     COLOR_2                 ;& No,  Check for save code
  633.                MOV     CL,SAVE_ATTRIBUTE       ;& Yes, Get back saved attribute
  634.                JMP     SHORT COLOR_3           ;& and set it
  635. COLOR_2:       DEC     CL                      ;& Is it @X00 save code
  636.                JNZ     COLOR_3                 ;& No,  just set it then
  637.                MOV     CL,ATTRIBUTE            ;& Yes, Save the attribute
  638.                MOV     SAVE_ATTRIBUTE,CL       ;&
  639.                JMP     FLUSH_END               ;& and flush it
  640. COLOR_3:       MOV     ATTRIBUTE,CL            ;@ Set Attribute
  641.                JMP     FLUSH_END               ;@ Clear Buffer
  642.  
  643. ;------------------------------------------------;@
  644. VARIABLE_SUB:  CMP     AL,'@'                  ;@ Is it another @
  645.                JB      SHORT_FLUSH             ;@ No, and not valid, so flush
  646.                JNZ     BUFFER_JUMP           ;&;@ No, Buffer the Char (indirect)
  647.                MOV     DX,OFFSET AT_VARIABLE_TABLE ;@ Point to Variable List
  648.                XOR     BX,BX                   ;@ Position in Variable List
  649. NEXT_VARI:     MOV     DI,DX                   ;@ Load DI
  650.                INC     BX                      ;@ Count the Variable
  651.                MOV     SI,OFFSET ESC_BUFFER    ;@ Point to our Variable
  652.                MOV     CX,OFFSET LAST_VARIABLE ;@ Point to End of list
  653.                SUB     CX,DI                   ;@ Minus our current location
  654.                MOV     AL,'@'                  ;@ We need to start on these
  655.                REPNE   SCASB                   ;@ so find one
  656.                JCXZ    SHORT_FLUSH             ;@ End of List? Yes
  657.                MOV     DX,DI                   ;@ No,Save Variable list pointer
  658.                DEC     DI                      ;@ No, Back up to the @
  659.                MOV     CX,ESC_COUNT            ;@ Length of Variable
  660.                REP     CMPSB                   ;@ See if this one matches?
  661.                JNZ     NEXT_VARI               ;@ Didn't match that one!
  662.                CMP     [DI],AL                 ;@ Last Character has to be an @
  663.                JNZ     NEXT_VARI               ;@ Nope
  664.                DEC     BX                      ;@ Back up 1
  665.                CMP     BX,11                   ;@ Is it an Action code
  666.                JA      NOT_ACTION              ;@ No
  667.                SHL     BX,1                    ;@ BX x 2 for proper offset
  668.                MOV     DI,OFFSET JUMP_TABLE    ;@ Point to command table
  669.                ADD     DI,BX                   ;@ Adjust to the desired command
  670.                JMP     EXECUTE                 ;@ Execute the command
  671. NOT_ACTION:    MOV     SI, OFFSET SUB_TABLE    ;@ Point to Sub Table
  672.                MOV     AX,BX                   ;@ Save Variable Number
  673.                MOV     CX,BX                   ;@ Copy Variable Number
  674.                XOR     BX,BX                   ;@ Zero Offset
  675.                XOR     DX,DX                   ;@ Zero out initial length
  676.                SUB     CX,11                   ;@ Adjust Variable Number
  677. NEXT_OFFSET:   ADD     BX,DX                   ;@ Add last Length to Offset
  678.                MOV     DL,[SI]                 ;@ Get Length
  679.                INC     SI                      ;@ Bump the pointer
  680.                LOOP    NEXT_OFFSET             ;@ Do all of them
  681.                MOV     CX,DX                   ;@ Get last Length
  682.                MOV     SI,OFFSET SUB_LIST      ;@ Point to the substitue buffer.
  683.                ADD     SI,BX                   ;@ Add Offset
  684.                SUB     AX,34                   ;@ Is It a String Variable
  685.                JB      IS_STRING               ;@ Yes, Flush our Substitute
  686.                CMP     AX,1                    ;@ Is it Date ot Time?
  687.                JBE     IS_TIMEDATE             ;@ No, It's a Number
  688.                SUB     AX,2                    ;@ Adjust Variable number
  689.                CALL    NUMBER_PARSE            ;@ Create a Numeric value then
  690.                JMP     SHORT VAR_END           ;@ Flush our Number
  691. IS_TIMEDATE:   CALL    MAKE_TIMEDATE           ;@
  692. IS_STRING:     MOV     DI,SI                   ;@ Copy Pointer to DI for SCASB
  693.                MOV     AL,0                    ;@ We look for a Zero
  694.                REPNE   SCASB                   ;@ Findit it
  695.                JNE     GOT_END                 ;@ Skip if we didn't hit a Zero
  696.                DEC     DI                      ;@ Back up if we did
  697. GOT_END:       MOV     CX,DI                   ;@ Get Current Location
  698.                SUB     CX,SI                   ;@ Subtract Starting Location
  699. VAR_END:       JMP     NEXT_FLUSH              ;@ Flush our Substitute
  700.  
  701. SHORT_FLUSH:   PUSH    AX                      ;& Save Character
  702.                CALL    FLUSH_BUFF2             ;@ Flush what we have now
  703.                POP     AX                      ;& Restore Character
  704.                JMP     ESC_STATE               ;& And save the new state
  705.  
  706. ;------------------------------------------------;@
  707. ATX_STATE:     MOV     BX,OFFSET COLOR_STATE   ;@ Assume 'X' Character
  708.                CMP     AL,"X"                  ;@ Is it X? If yes, store
  709.                JZ      SHORT_STORE             ;@ char. and next state.
  710.                CMP     AL,'@'                  ;@ Is it another '@' already?
  711.                JZ      WRITE_CHAR              ;@ Yes!
  712.                CMP     AL,ESC_CHAR             ;& Is it an Escape
  713.                JE      SHORT_FLUSH             ;& Yes, so flush buffer & restart
  714.                MOV     BX,OFFSET VARIABLE_SUB  ;@ No, Must be a Variable
  715. SHORT_STORE:   JMP     STORE_STATE             ;@ Store the state
  716. endif                                             ;$
  717. ;------------------------------------------------;
  718. ; Slow video writes are via BIOS Write TTY.      ;
  719. ;------------------------------------------------;
  720.  
  721. WRITE_CHAR:    CMP     AL,BELL                 ;Let BIOS process BS and BELL.
  722.                JZ      WRITE_TTY
  723.                CMP     AL,BS
  724.                JZ      WRITE_TTY
  725.  
  726.                CALL    GET_BIOS_DATA           ;Get BIOS video data.
  727.                CMP     AL,TAB                  ;Is character a TAB?
  728.                JNZ     CK_ACTIVE               ;If no, process normally.
  729.                MOV     CX,CURSOR_POSN          ;Else, expand TAB to
  730.                AND     CX,7                    ; appropriate space characters.
  731.                NEG     CX
  732.                ADD     CX,8
  733. NEXT_TAB:      PUSH    CX
  734.                MOV     AL,SPACE
  735.                CALL    CK_ACTIVE
  736.                POP     CX
  737.                LOOP    NEXT_TAB
  738.                RET
  739.  
  740. CK_ACTIVE:     TEST    STATUS,OFF              ;Is ANSI OFF?
  741.                JNZ     WRITE_TTY               ;If yes, write via BIOS TTY.
  742. CK_FAST:       CALL    CK_SLOW_TEXT            ;Is ANSI SLOW or in graphics
  743.                JNC     WRITE_FAST              ; mode? If no, write fast.
  744.  
  745.                CMP     AL,CR                   ;Let BIOS handle CR and LF.
  746.                JZ      WRITE_TTY
  747.                CMP     AL,LF
  748.                JZ      WRITE_TTY
  749.  
  750. WRITE_SLOW:    PUSH    AX                      ;Else, write character/attribute
  751.                MOV     CX,1                    ; at current cursor position
  752.                MOV     BH,ACTIVE_PAGE          ; via BIOS.
  753.                MOV     BL,ATTRIBUTE
  754.                MOV     AH,9
  755.                INT     10H
  756.                POP     AX
  757.  
  758.                CMP     LINE_WRAP,ON            ;Is line wrap on?
  759.                JZ      TTY                     ;If yes, continue.
  760.                MOV     CX,CRT_COLS             ;Else, cursor at rightmost
  761.                DEC     CL                      ; column?
  762.                CMP     CL,CURSOR_COL           ;If yes, continue, else
  763.                JNZ     TTY                     ; return without writing.
  764.                RET
  765.  
  766. ;------------------------------------------------;
  767.  
  768. WRITE_TTY:     MOV     BL,7                    ;Attribute in graphics mode.
  769. TTY:           MOV     AH,0EH
  770.                INT     10H
  771.                RET
  772.  
  773. ;----------------------------------------------------------------------------;
  774. ; Fast screen writes are directly to the video buffer without retrace check. ;
  775. ;----------------------------------------------------------------------------;
  776.  
  777. WRITE_FAST:    PUSH    ES                      ;Preserve extra segment.
  778.                MOV     DX,CURSOR_POSN          ;Retrieve cursor position.
  779.                CMP     AL,CR                   ;Carriage return?
  780.                JNZ     CK_LINEFEED             ;If no, check linefeed.
  781.                XOR     DL,DL                   ;Else, cursor to first column.
  782.                JMP     SHORT UPDATE_CURSOR
  783. CK_LINEFEED:   CALL    VIDEO_SETUP             ;Calculate video address.
  784.                CMP     AL,LF                   ;Linefeed?
  785.                JZ      NEXT_ROW                ;If yes, next row.
  786.  
  787.                MOV     AH,ATTRIBUTE            ;Retrieve attribute.
  788.                STOSW                           ;Put char/attrib in video buffer.
  789.                INC     DL                      ;Increment cursor column.
  790.                CMP     DL,BYTE PTR CRT_COLS    ;End of row?
  791.                JB      UPDATE_CURSOR           ;If no, update cursor.
  792.  
  793.                CMP     LINE_WRAP,OFF           ;Else, line wrap off?
  794.                JZ      FAST_END                ;If yes, don't move cursor.
  795.                XOR     DL,DL                   ;Else, column zero.
  796. NEXT_ROW:      INC     DH                      ;Next row.
  797.                CALL    INFORMATION             ;Get displayable row info.
  798.                CMP     DH,AL                   ;Beyond the bottom of screen?
  799.                JBE     UPDATE_CURSOR           ;If no, update cursor.
  800.  
  801.                DEC     DH                      ;Else, cursor to original row.
  802.                MOV     AX,CRT_COLS             ;. Get number of columns
  803.                PUSH    DX                      ;. Save Cursor position
  804.                PUSH    AX                      ;. Save Columns
  805.                SHL     AX,1                    ;. Twice for Char/Attribute
  806.                MOV     SI,AX                   ;. Starting offset in SI
  807.                MOV     DL,START_SCROLL         ;. Where we allow scroll to start
  808.                MUL     DL                      ;. Calculate offset in AX
  809.                SUB     DH,DL                   ;. Reduce line count
  810.                MOV     DI,CRT_START            ;Point destination to top.
  811.                ADD     DI,AX                   ;. Add offset
  812.                ADD     SI,DI                   ;. Point source to second row
  813.                POP     AX                      ;. Get Back Columns
  814.                PUSH    AX                      ;. Save it again
  815.                MUL     DH                      ;Times displayable rows - 1.
  816.                MOV     CX,AX                   ; equals char/attrib to scroll.
  817.                PUSH    DS                      ;Save data segment and
  818.                PUSH    ES                      ; point to video segment.
  819.                POP     DS
  820.                REP     MOVSW                   ;Scroll the screen.
  821.                POP     DS                      ;Restore data segment.
  822.                POP     CX                      ;Retrieve CRT columns.
  823.                POP     DX                      ;.Get back Cursor info
  824.                MOV     AL,SPACE                ;Write space/attrib to
  825.                MOV     AH,ATTRIBUTE            ; bottom row.
  826.                REP     STOSW
  827.  
  828. UPDATE_CURSOR: CALL    SET_CURSOR              ;Update the cursor position.
  829. FAST_END:      POP     ES                      ;Restore extra segment.
  830.                RET
  831. if PCB                                            ;$
  832. ;@************ SUPPORT ROUTINES *************;
  833.  
  834. QOFF:          MOV     AL,0FFH                 ;& Show QOFF
  835.                JMP     SHORT QON2              ;&
  836. QON:           XOR     AL,AL                   ;& Show QON
  837. QON2:          MOV     Q_STATE,AL              ;& Store the state
  838.                RET                             ;& All done
  839.  
  840. BEEP:          MOV     AL,7                    ;@
  841.                JMP     WRITE_CHAR              ;@
  842. MORE:          MOV     AX,MORE_DELAY           ;@
  843.                JMP     SHORT PAUSE2            ;@
  844. PAUSE:         MOV     AX,PAUSE_DELAY          ;@
  845. PAUSE2:        CMP     Q_STATE,0               ;& Are we at a QOFF state
  846.                JNZ     WAIT1                   ;& Yes, then these are WAITs
  847.                MOV     SI,OFFSET MORE_PROMPT   ;@ Point to More? Prompt
  848.                MOV     CX,MORE_LENGTH          ;@ Get the Length of it
  849.                JMP     SHORT WAIT2             ;@ Go Wait
  850. WAIT1:         MOV     AX,WAIT_DELAY           ;@
  851.                MOV     SI,OFFSET WAIT_PROMPT   ;@ Point to Wait Prompt
  852.                MOV     CX,WAIT_LENGTH          ;@ Get the Length of it
  853. WAIT2:         MOV     PAUSE_TIMER,AX          ;@
  854. ;               PUSH    CX                      ;@ Save Length
  855. WAIT2_LOOP:    LODSB                           ;@ Get Character
  856.                PUSH    CX                      ;@
  857.                PUSH    SI                      ;@
  858.                CALL    WRITE_CHAR              ;@ Output it
  859.                POP     SI                      ;@
  860.                POP     CX                      ;@
  861.                LOOP    WAIT2_LOOP              ;@ Do all the Characters
  862. WAIT_LOOP:     MOV     AH,1                    ;@ KeyBoard Status
  863.                INT     16H                     ;@ Keyboard I/O Services
  864.                JNZ     CONTINUE                ;@ Key Hit!
  865.                CMP     PAUSE_TIMER,0           ;@ Timer Run out?
  866.                JNE     WAIT_LOOP               ;@ No
  867.                JMP     SHORT WAIT3             ;@ Yes
  868. CONTINUE:      MOV     AH,0                    ;@ KeyBoard Read
  869.                INT     16H                     ;@ Keyboard I/O Services
  870. WAIT3:                                         ;@
  871.                XOR     CL,CL                   ;@ Clear the Attribute
  872.                XCHG    CL,ATTRIBUTE            ;&  and
  873.                PUSH    CX                      ;&    save it too
  874.                MOV     DX,CURSOR_POSN          ;& Get Cursor
  875.                MOV     DL,0                    ;& First column
  876.                CALL    SET_CURSOR              ;& Set the new Cursor
  877.                CALL    ERASE_2                 ;& Erase the line
  878. ;&
  879. ;& The following lines (and the PUSH CX above) will clear only the PROMPT
  880. ;& and leave the cursor where it was when the prompt appears. This was
  881. ;& different than PCBoard 14.5 so I changed it to clear the entire line
  882. ;& via the above four lines. Left the old code in case someome wanted it.
  883. ;&
  884. ;&               POP     CX                      ;@ Get back Length
  885. ;&ERASE_LOOP:    PUSH    CX                      ;@ Save it again
  886. ;&               MOV     AL,BS                   ;@ Send BS
  887. ;&               CALL    WRITE_CHAR              ;@  character
  888. ;&               MOV     AL,' '                  ;@  and then space
  889. ;&               CALL    WRITE_CHAR              ;@  character to erase
  890. ;&               MOV     AL,BS                   ;@  then BS again
  891. ;&               CALL    WRITE_CHAR              ;@  to backup.
  892. ;&               POP     CX                      ;@ get back length again
  893. ;&               LOOP    ERASE_LOOP              ;@ Erase entire prompt.
  894.                POP     CX                      ;& Restore
  895.                MOV     ATTRIBUTE,CL            ;&  the Attribute
  896.                RET                             ;@
  897. AUTOOFF:       MOV     AX,WAIT_DELAY           ;@ Restore More to a Wait
  898.                JMP     SHORT AUTO2             ;@
  899. AUTOMORE:      MOV     AX,PAUSE_DELAY          ;@ Make More a Pause
  900. AUTO2:         MOV     MORE_DELAY,AX           ;@
  901. SKIP_IT:       RET                             ;@
  902. endif                                             ;$
  903. ;************* SUPPORT ROUTINES *************;
  904.  
  905. CK_QUOTE:      MOV     BX,OFFSET QUOTE_STATE   ;Assume quote state.
  906.                MOV     AH,DOUBLE_QUOTE
  907.                CMP     AL,AH                   ;Is it double quote?
  908.                JZ      GOT_QUOTE               ;If yes, string delimiter.
  909.                MOV     AH,SINGLE_QUOTE         ;Is it single quote?
  910.                CMP     AL,AH                   ;Is yes, string delimiter.
  911.                JNZ     QUOTE_END               ;Else, return ZR = 0.
  912. GOT_QUOTE:     MOV     QUOTE_TYPE,AH           ;Store as matching string end.
  913. QUOTE_END:     RET
  914.  
  915. ;------------------------------------------------;
  916.  
  917. ACCUMULATE:    PUSH    AX                      ;Preserve number character.
  918.                SUB     AL,"0"                  ;Convert ASCII to binary.
  919.                MOV     CL,AL                   ;Save the number.
  920.                MOV     AX,10                   ;Multiply previous count by 10.
  921.                MOV     BX,NUMBER_COUNT
  922.                MUL     BYTE PTR NUMBER_BUFFER[BX]
  923.                ADD     AL,CL                            ;Add in new number
  924.                MOV     BYTE PTR NUMBER_BUFFER[BX],AL    ; and store.
  925.                POP     AX
  926.                RET
  927. if PCB                                            ;$
  928. ;------------------------------------------------;@
  929.  
  930. ACCUM_COLOR:   PUSH    AX                      ;@ Preserve number character.
  931.                SUB     AL,"0"                  ;@ Convert ASCII to hex
  932.                MOV     AH,BYTE PTR NUMBER_BUFFER ;@ Get current number
  933.                SHL     AH,1                      ;@ Shift left 4 bits
  934.                SHL     AH,1                      ;@
  935.                SHL     AH,1                      ;@
  936.                SHL     AH,1                      ;@
  937.                OR      AH,AL                     ;@ Add in new number
  938.                MOV     BYTE PTR NUMBER_BUFFER,AH ;@ and store.
  939.                MOV     CL,AH                     ;@ Return with Color in CL
  940.                POP     AX                        ;@
  941.                RET                               ;@
  942.  
  943. NUMBER_PARSE:  MOV  BX,[SI]                 ;@ Get low word
  944.                MOV  DX,AX                   ;@ Save Variable Number
  945.                XOR  AX,AX                   ;@ Assume Integer
  946.                CMP  CX,4                    ;@ Is that a Long Integer?
  947.                JNE  SHORT_INT               ;@ No, Integer
  948.                MOV  AX,[SI + 2]             ;@ Yes, Get high word
  949. SHORT_INT:     MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  950.                MOV  CX,10                   ;@ Set divisor to 10
  951.                XOR  SI,SI                   ;@ Clear SI as counter
  952.                MOV  COMMA,2                 ;@ Assume a Ratio
  953.                CMP  DX,2                    ;@ Is it a Ratio?
  954.                JB   GETDIGIT                ;@ No
  955. RESET_COMMA:   MOV  COMMA,4                 ;@ Set Comma Counter
  956. GETDIGIT:      DEC  DI                      ;@ Point DI at correct character
  957.                INC  SI                      ;@ Register that we have a character
  958.                DEC  COMMA                   ;@ Do we need a Comma?
  959.                JNZ  NO_COMMA                ;@ No
  960.                MOV  BYTE PTR [DI],','       ;@ Yes, So Put one in!
  961.                JMP  RESET_COMMA             ;@ And restart the Comma count.
  962. NO_COMMA:      XOR  DX,DX                   ;@ Clear DX to take remainder
  963.                DIV  CX                      ;@ Divide AX first (High word)
  964.                MOV  BP,AX                   ;@ Save quotient
  965.                MOV  AX,BX                   ;@ Get low word
  966.                DIV  CX                      ;@ DX had leftover from first divide
  967.                MOV  BX,AX                   ;@ Save quotient
  968.                MOV  AX,BP                   ;@ Put high word back
  969.                ADD  DL,30h                  ;@ Make it an ASCII digit from remainder
  970.                MOV  [DI],DL                 ;@ Put it in our string
  971.                OR   AX,AX                   ;@ Is high word zero?
  972.                JNZ  GETDIGIT                ;@ No keep going
  973.                OR   BX,BX                   ;@ Is low word zero?
  974.                JNZ  GETDIGIT                ;@ No keep going
  975.                MOV  CX,SI                   ;@ Digit count to CX
  976.                MOV  SI,DI                   ;@ String Pointer to SI
  977.                MOV  DI, OFFSET PARSE_BUFFER ;@ Point DI at number space
  978.                CMP  BYTE PTR [DI][-2],','   ;@ Was it a Ratio
  979.                JNE  NOT_RATIO               ;@ No, nevermind
  980.                MOV  BYTE PTR [DI][-2],'.'   ;@ Change comma to Decimal
  981.                MOV  BYTE PTR [DI],":"       ;@ Yes, Add ':1' to it
  982.                MOV  BYTE PTR [DI][1],"1"    ;@
  983.                ADD  CX,2                    ;@ Account for two more characers
  984. NOT_RATIO:     RET                          ;@
  985.  
  986. MAKE_TIMEDATE: MOV  DI, OFFSET NUMBER_BUFFER ;@ Point to Number Buffer
  987.                MOV  SI,DI            ;@ Save it in SI too
  988.                JE   MAKE_TIME        ;@ It was TIME on Entry!
  989.                MOV  CX,8             ;@ It was DATE! Length = 8
  990.                PUSH CX               ;@ Save Length
  991.                MOV  AH,04H           ;@ Get date service
  992.                INT  1AH              ;@ Call BIOS - return codes as follows:
  993.                PUSH CX               ;@ CH = Century (19-20)  CL = Year (00-99)
  994.                PUSH DX               ;@ DH = Month   (1-12)   DL = Day  (00-31)
  995.                MOV  AL,DH            ;@ Month
  996.                CALL ASCII            ;@ Convert byte to ASCII digits
  997.                MOV  AL,'-'           ;@
  998.                STOSB                 ;@
  999.                POP  AX               ;@ Day - was DX when pushed
  1000.                CALL ASCII            ;@ Convert byte to ASCII digits
  1001.                MOV  AL,'-'           ;@
  1002.                STOSB                 ;@
  1003.                POP  AX               ;@ Year - was CX when pushed
  1004.                POP  CX               ;@ Restore Length
  1005.                JMP  SHORT ASCII      ;@ Convert byte to ASCII digit
  1006.  
  1007. MAKE_TIME:     MOV  CX,5             ;@ Length = 5
  1008.                PUSH CX               ;@ Save Length
  1009.                MOV  AH,02H           ;@ Get time service
  1010.                INT  1AH              ;@ Call BIOS - return codes as follows:
  1011.                PUSH CX               ;@ CH = Hours   (0-23)   CL = Minutes (0-59)
  1012.                MOV  AL,CH            ;@ Hours
  1013.                CALL ASCII            ;@ Convert byte to ASCII digits
  1014.                MOV  AL,':'           ;@
  1015.                STOSB                 ;@
  1016.                POP  AX               ;@ Minutes - was CX when pushed
  1017.                POP  CX               ;@ Restore Length
  1018. ASCII:         MOV  AH,AL            ;@ Need to get BCD Digits
  1019.                SHR  AL,1             ;@  MSD in AL
  1020.                SHR  AL,1             ;@   lower
  1021.                SHR  AL,1             ;@     4
  1022.                SHR  AL,1             ;@     Bits
  1023.                AND  AH,0FH           ;@ And LSD in AH cleanly
  1024.                OR   AX,3030H         ;@ Convert to ASCII
  1025.                STOSW                 ;@ Stuff Digits into Buffer (in reverse)
  1026.                RET                   ;@ SI Points to String Data
  1027. endif                                   ;$
  1028. ;---------------------------------------------------------------------------;
  1029. ; OUTPUT:  CY = 1 if write SLOW mode or in graphics mode; CY = 0 otherwise. ;
  1030. ;---------------------------------------------------------------------------;
  1031.  
  1032. CK_SLOW_TEXT:  TEST    STATUS,SLOW
  1033.                JNZ     SLOW_MODE
  1034.                CMP     CRT_MODE,7
  1035.                JZ      TEXT_MODE
  1036.                CMP     CRT_MODE,3
  1037.                JA      SLOW_MODE
  1038. TEXT_MODE:     CLC
  1039.                RET
  1040.  
  1041. SLOW_MODE:     STC
  1042.                RET
  1043.  
  1044. ;-------------------------------------;
  1045. ; OUTPUT:  AL = Screen rows minus one ;
  1046. ;-------------------------------------;
  1047.  
  1048. INFORMATION:   PUSH    DS                      ;Save data segment.
  1049.                MOV     AX,40H                  ;Point to BIOS data.
  1050.                MOV     DS,AX
  1051.                MOV     AL,DS:[84H]             ;Retrieve rows - 1.
  1052.                OR      AL,AL                   ;BIOS supported?
  1053.                JNZ     INFO_END                ;If yes, done here.
  1054.                MOV     AL,24                   ;Else, assume 25 lines.
  1055. INFO_END:      POP     DS
  1056.                RET
  1057.  
  1058. ;------------------------------------------------------------------------------;
  1059. ; INPUT:  DX = Cursor position.                                                ;
  1060. ; OUTPUT: ES = Video buffer segment; DI = Video buffer offset; AX,DX preserved ;
  1061. ;------------------------------------------------------------------------------;
  1062.  
  1063. VIDEO_SETUP:   PUSH    AX
  1064.                MOV     AX,CRT_COLS             ;Retrieve CRT columns.
  1065.                MUL     DH                      ;Times cursor row.
  1066.                MOV     BL,DL
  1067.                XOR     BH,BH
  1068.                ADD     AX,BX                   ;Plus cursor column.
  1069.                SHL     AX,1                    ;Times two for attribute.
  1070.                MOV     DI,CRT_START            ;Plus starting video offset.
  1071.                ADD     DI,AX                   ;Equals destination.
  1072.  
  1073.                MOV     BX,0B000H               ;Assume mono card.
  1074.                CMP     ADDR_6845,3B4H          ;Is it mono port?
  1075.                JZ      VIDEO_SEGMENT           ;If yes, guessed right.
  1076.                ADD     BX,800H                 ;Else, point to color segment.
  1077. VIDEO_SEGMENT: MOV     ES,BX
  1078.                POP     AX
  1079.                RET
  1080.  
  1081. ;------------------------------------------------;
  1082. ; Move BIOS video data into our data segment.    ;
  1083. ;------------------------------------------------;
  1084.  
  1085. GET_BIOS_DATA: PUSH    DS
  1086.                PUSH    DI                      ;Point to BIOS data segment.
  1087.                MOV     BX,40H
  1088.                MOV     DS,BX
  1089.                MOV     SI,BIOS_ACTIVE_PAGE     ;Start with active page.
  1090.                MOV     DI,OFFSET ACTIVE_PAGE
  1091.                MOVSB                           ;Retrieve active page
  1092.                MOVSW                           ; and address of 6845 port.
  1093.                MOV     SI,BIOS_CRT_MODE        ;Retrieve CRT mode, CRT columns,
  1094.                MOV     CX,CRT_DATA_LENGTH      ; CRT length, CRT start.
  1095.                REP     MOVSB
  1096.                MOV     BL,ES:ACTIVE_PAGE       ;Use active page as index
  1097.                XOR     BH,BH                   ; of active cursor position.
  1098.                SHL     BX,1
  1099.                ADD     SI,BX
  1100.                MOVSW
  1101.                POP     DI
  1102.                POP     DS
  1103.                RET
  1104.  
  1105. ;----------------------------------------------------------------------------;
  1106. ; OUTPUT: BL = First parameter; BH = Second parameter; DX = cursor position. ;
  1107. ;----------------------------------------------------------------------------;
  1108.  
  1109. ADJUST_NUMBER: MOV     BX,WORD PTR NUMBER_BUFFER
  1110.                OR      BH,BH
  1111.                JNZ     ADJUST_AL               ;If either parameter zero,
  1112.                INC     BH                      ; increment to convert
  1113. ADJUST_AL:     OR      BL,BL                   ; to base one.
  1114.                JNZ     ADJUST_END
  1115.                INC     BL
  1116. ADJUST_END:    MOV     DX,CURSOR_POSN          ;Return cursor position.
  1117.                RET
  1118.  
  1119. ;--------------------------------------------------------------------------;
  1120. ; INPUT:  AX = number; BP = 0 if console output; BP = 1 if storage output. ;
  1121. ;--------------------------------------------------------------------------;
  1122.  
  1123. DECIMAL_OUT:   MOV     BX,10                   ;Divisor of ten.
  1124.                XOR     CX,CX                   ;Zero in counter.
  1125. NEXT_COUNT:    XOR     DX,DX                   ;Zero in high half.
  1126.                DIV     BX                      ;Divide by ten.
  1127.                ADD     DL,"0"                  ;Convert to ASCII.
  1128.                PUSH    DX                      ;Save results.
  1129.                INC     CX                      ;Also increment count.
  1130.                CMP     AX,0                    ;Are we done?
  1131.                JNZ     NEXT_COUNT              ;Continue until zero.
  1132.                OR      BP,BP                   ;If BP zero, output to screen.
  1133.                JNZ     DEVICE_OUTPUT           ;Else, store in buffer.
  1134.  
  1135. REPORT_OUTPUT: POP     AX                      ;Retrieve number.
  1136.                CALL    PRINT_CHAR              ;Display it.
  1137.                LOOP    REPORT_OUTPUT
  1138.                RET
  1139.  
  1140. DEVICE_OUTPUT: CMP     CX,2                    ;Two digits?
  1141.                JZ      TWO_DIGITS              ;If yes, process normally.
  1142.                MOV     AL,"0"                  ;Else, store leading zero.
  1143.                STOSB
  1144.  
  1145. TWO_DIGITS:    POP     AX                      ;Retrieve number.
  1146.                STOSB                           ;Store it
  1147.                LOOP    TWO_DIGITS
  1148.                RET
  1149.  
  1150. ;************* ANSI COMMAND SUBSET *************;
  1151.  
  1152. CLS:           MOV     BH,7                    ;Assume normal attribute.
  1153.                MOV     BL,BYTE PTR CRT_MODE    ;Get current video mode.
  1154.                CMP     BL,4
  1155.                JBE     CK_CLS_STATUS           ;If text mode then check if
  1156.                CMP     BL,7                    ; ANSI active.
  1157.                JZ      CK_CLS_STATUS
  1158.                XOR     BH,BH                   ;Else, use black attribute
  1159.                TEST    STATUS,OFF
  1160.                JNZ     CLS_SLOW                ;If ANSI inactive, via BIOS.
  1161.                JMP     SHORT CK_CLS_SLOW       ;Else, check if FAST or SLOW.
  1162.  
  1163. CK_CLS_STATUS: TEST    STATUS,OFF              ;Is ANSI OFF?
  1164.                JNZ     CLS_SLOW                ;If yes, CLS via BIOS.
  1165.                MOV     BH,ATTRIBUTE            ;Else, current attribute.
  1166. CK_CLS_SLOW:   CALL    CK_SLOW_TEXT
  1167.                JC      CLS_SLOW                ;If ANSI SLOW, via BIOS.
  1168.  
  1169. CLS_FAST:      MOV     AH,BH                   ;Else, attribute in high half.
  1170.                MOV     AL,SPACE                ;Space character in low half.
  1171.                XOR     DX,DX                   ;Cursor position home.
  1172.                MOV     DH,START_SCROLL         ;$ protect lines
  1173.                CALL    VIDEO_SETUP             ;Calculate video address.
  1174.                MOV     CX,CRT_LEN              ;Retrieve CRT length.
  1175.                SHR     CX,1                    ;Times two for attribute.
  1176.                REP     STOSW                   ;Write directly to video buffer.
  1177.                JMP     SHORT SET_CURSOR        ;Set the cursor top left corner.
  1178.  
  1179. CLS_SLOW:      CALL    INFORMATION             ;Get displayable rows.
  1180.                MOV     DH,AL                   ;Store in DH.
  1181.                MOV     DL,BYTE PTR CRT_COLS    ;Retrieve CRT columns.
  1182.                DEC     DL                      ;Adjust to zero base.
  1183.                XOR     CX,CX                   ;Scroll active page.
  1184.                MOV     AX,600H
  1185.                INT     10H
  1186.                XOR     DX,DX                   ;Home the cursor.
  1187.                JMP     SHORT SET_CURSOR
  1188.  
  1189. ;------------------------------------------------;
  1190. CURS_POSITION:                                 ;These two commands are the same.
  1191. HORZ_VERT_POS: CALL    INFORMATION             ;Returns AL = screen rows.
  1192.                CALL    ADJUST_NUMBER           ;Returns BL,BH = parameters.
  1193.                SUB     BX,101H                 ;Zero based.
  1194.                CMP     BL,AL                   ;If cursor request within
  1195. ;$             JA      CURSOR_END              ; boundaries of screen, set it.
  1196.                JBE     ROWOK                   ;$boundaries of screen, set it.
  1197.                MOV     BL,AL                   ;$Set to last row
  1198. ROWOK:         CMP     BH,BYTE PTR CRT_COLS    ;$
  1199. ;$             JAE     CURSOR_END
  1200.                JB      COLOK                   ;$
  1201.                MOV     BH,BYTE PTR CRT_COLS    ;$Set to
  1202.                DEC     BH                      ;$       last column
  1203. COLOK:         XCHG    BH,BL                   ;
  1204.                MOV     DX,BX
  1205.  
  1206. SET_CURSOR:    MOV     BH,ACTIVE_PAGE          ;Set cursor via BIOS.
  1207.                MOV     AH,2
  1208.                INT     10H
  1209. CURSOR_END:    RET
  1210.  
  1211. ;------------------------------------------------;
  1212.  
  1213. CURSOR_UP:     CALL    ADJUST_NUMBER           ;Move cursor up one or more rows
  1214.                OR      DH,DH                   ; without changing column.
  1215.                JZ      CURSOR_END              ;If already at top, ignore.
  1216.                SUB     DH,BL
  1217.                JNC     SET_CURSOR              ;Stay in bounds.
  1218.                XOR     DH,DH
  1219.                JMP     SHORT SET_CURSOR
  1220.  
  1221. ;------------------------------------------------;
  1222.  
  1223. CURSOR_DOWN:   CALL    INFORMATION             ;Returns AL = screen rows.
  1224.                CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1225.                CMP     DH,AL                   ;Move cursor down requested
  1226.                JZ      CURSOR_END              ; rows without changing column.
  1227.                ADD     DH,BL
  1228.                CMP     DH,AL
  1229.                JNA     SET_CURSOR
  1230.                MOV     DH,AL                   ;Stay in bounds.
  1231.                JMP     SHORT SET_CURSOR
  1232.  
  1233. ;------------------------------------------------;
  1234.  
  1235. CURS_FORWARD:  CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1236.                MOV     BH,BYTE PTR CRT_COLS    ;Retrieve displayable columns.
  1237.                DEC     BH                      ;Adjust to zero base.
  1238.                CMP     DL,BH                   ;Move cursor forward one or more
  1239.                JZ      CURSOR_END              ; columns without changing row.
  1240.                ADD     DL,BL
  1241.                CMP     DL,BH
  1242.                JNA     SET_CURSOR
  1243.                MOV     DL,BH                   ;Stay in bounds.
  1244.                JMP     SHORT SET_CURSOR
  1245.  
  1246. ;------------------------------------------------;
  1247.  
  1248. CURS_BACKWARD: CALL    ADJUST_NUMBER           ;Returns BL,BH =nos.; DX = cursor
  1249.                OR      DL,DL                   ;Move cursor backward one or
  1250.                JZ      CURSOR_END              ; more columns without changing
  1251.                SUB     DL,BL                   ; row.  Ignore if already left.
  1252.                JNC     SET_CURSOR
  1253.                XOR     DL,DL                   ;Stay in bounds.
  1254.                JMP     SHORT SET_CURSOR
  1255.  
  1256. ;--------------------------------------------------------;
  1257. ; Report cursor position via console; Format: ESC[#;#R   ;
  1258. ;--------------------------------------------------------;
  1259.  
  1260. DEVICE_STATUS: MOV     DI,OFFSET DEVICE_STATUS_BUFFER
  1261.                MOV     AL,ESC_CHAR
  1262.                STOSB                           ;Store leading Esc, bracket
  1263.                MOV     AL,"["                  ;in special Device Status Buffer.
  1264.                STOSB
  1265.  
  1266.                MOV     AL,CURSOR_ROW           ;Retrieve cursor row.
  1267.                XOR     AH,AH                   ;Zero in high half.
  1268.                INC     AX                      ;Convert to base one.
  1269.                MOV     BP,1                    ;Flag as storage.
  1270.                CALL    DECIMAL_OUT             ;Convert to ASCII.
  1271.                MOV     AL,";"                  ;Store delimiting semi-colon.
  1272.                STOSB
  1273.                MOV     AL,CURSOR_COL           ;Do same with cursor column.
  1274.                XOR     AH,AH
  1275.                INC     AX
  1276.                CALL    DECIMAL_OUT
  1277.                MOV     AL,"R"                  ;Add command character
  1278.                STOSB
  1279.                MOV     AL,CR                   ; and carriage return.
  1280.                STOSB
  1281.                SUB     DI,OFFSET DEVICE_STATUS_BUFFER   ;Setup for console out.
  1282.                MOV     REASSIGN_COUNT,DI
  1283.                MOV     REASSIGN_POS,OFFSET DEVICE_STATUS_BUFFER
  1284.                MOV     REASSIGN_FLAG,ON
  1285.                MOV     REMOVE_FLAG,OFF
  1286.                RET
  1287.  
  1288. ;------------------------------------------------;
  1289.  
  1290. SAVE_CURSOR:   MOV     DX,CURSOR_POSN
  1291.                MOV     SAVE_POSITION,DX
  1292.                RET
  1293.  
  1294. ;------------------------------------------------;
  1295.  
  1296. RESTORE_CURS:  MOV     DX,SAVE_POSITION
  1297.                JMP     SET_CURSOR
  1298.  
  1299. ;------------------------------------------------;
  1300.  
  1301. ERASE_IN_LINE: MOV     DX,CURSOR_POSN          ;Erase from the cursor to
  1302. ERASE_2:       MOV     CX,CRT_COLS             ;& the end of the line, including
  1303.                SUB     CL,DL                   ; the current cursor position.
  1304.                CALL    CK_SLOW_TEXT
  1305.                JC      ERASE_SLOW              ;If ANSI ON and not graphics,
  1306.                CALL    VIDEO_SETUP             ; write directly to video buffer
  1307.                MOV     AL,SPACE                ; with space/attribute.
  1308.                MOV     AH,ATTRIBUTE
  1309.                REP     STOSW
  1310.                RET
  1311.  
  1312. ERASE_SLOW:    MOV     CX,DX                   ;Else, erase SLOW via
  1313.                MOV     DL,BYTE PTR CRT_COLS    ; BIOS scroll active page.
  1314.                DEC     DL
  1315.                MOV     BH,ATTRIBUTE
  1316.                MOV     AX,601H
  1317.                INT     10H
  1318.                RET
  1319.  
  1320. ;------------------------------------------------;
  1321. ;            Set Graphics Rendition              ;
  1322. ;------------------------------------------------;
  1323.  
  1324. SGR:           MOV     SI,OFFSET NUMBER_BUFFER     ;Point to number parameters.
  1325. NEXT_SGR:      LODSB                               ;Retrieve parameter.
  1326.                MOV     DI,OFFSET ATTRIBUTE_TABLE   ;Look up attribute in
  1327.                MOV     CX,ATTRIBUTE_LENGTH         ; translation table.
  1328.                REPNZ   SCASB
  1329.                JNZ     SGR_LOOP
  1330.  
  1331.                MOV     DI,OFFSET ATTRIBUTE_END
  1332.                SHL     CX,1
  1333.                SUB     DI,CX
  1334.                MOV     AX,[DI]
  1335.                AND     ATTRIBUTE,AL            ;If match, AND with strip mask.
  1336.                OR      ATTRIBUTE,AH            ;OR with add mask.
  1337. SGR_LOOP:      DEC     NUMBER_COUNT            ;Do all parameters.
  1338.                JNZ     NEXT_SGR
  1339.                RET
  1340.  
  1341. ;------------------------------------------------;
  1342.  
  1343. SET_MODE:      MOV     AH,ON                   ;Assume command 7,
  1344.                JMP     SHORT CK_WRAP           ; turn line wrap on.
  1345.  
  1346. ;------------------------------------------------;
  1347.  
  1348. RESET_MODE:    MOV     AH,OFF                     ;Assume turn line wrap off.
  1349. CK_WRAP:       MOV     AL,BYTE PTR NUMBER_BUFFER  ;Retrieve number parameter.
  1350.                CMP     AL,7                       ;Is it 7?
  1351.                JZ      SET_WRAP                ;If yes, set wrap mode.
  1352.                JB      DO_MODE                 ;1 - 6 valid modes.
  1353.                CMP     AL,14                   ;14 - 16 valid modes.
  1354.                JB      MODE_END
  1355.                CMP     AL,19
  1356.                JA      MODE_END                ;If above 16, illegal.
  1357. DO_MODE:       XOR     AH,AH                   ;Else, set video mode
  1358.                INT     10H                     ; to parameter.
  1359.                RET
  1360.  
  1361. SET_WRAP:      MOV     LINE_WRAP,AH
  1362. MODE_END:      RET
  1363.  
  1364. ;--------------------------------------------------------------------;
  1365. ; Keyboard Key Reassignment:  First convert ASCII numbers to binary, ;
  1366. ; parse out delimiting semi-colons, and quote string delimiters.     ;
  1367. ;--------------------------------------------------------------------;
  1368.  
  1369. REASSIGNMENT:  TEST    STATUS,POFF             ;:If assignment are OFF,
  1370.                JZ      NOT_POFF                ;:   then exit as if
  1371.                JMP     ASSIGN_FLUSH            ;:   we are out of room.
  1372. NOT_POFF:                                      ;:
  1373.                MOV     CX,ESC_COUNT            ;Retrieve length of Esc sequence.
  1374.                DEC     CX                          ;Adjust.
  1375.                MOV     SI,OFFSET ESC_BUFFER + 2    ;Point past Esc, bracket.
  1376.                MOV     DI,OFFSET PARSE_BUFFER      ;Point to parse storage.
  1377. NEXT_STRING:   MOV     QUOTE_TYPE,0                ;Reset quote type.
  1378. NEXT_NUM:      XOR     DL,DL                   ;Use DL to carry number; init = 0
  1379.                XOR     BP,BP                   ;Use BP as number flag.
  1380. NEXT_PARAM:    LODSB                           ;Retrieve a byte.
  1381.                DEC     CX                      ;Decrement string length counter.
  1382.                JZ      PARSE_END               ;If zero, done.
  1383.                MOV     AH,QUOTE_TYPE           ;Else, retrieve quote type.
  1384.                OR      AH,AH                   ;If zero, not in string.
  1385.                JNZ     QUOTE_MODE              ;Else, go to string mode.
  1386.                CALL    CK_QUOTE                ;Is character a quote?
  1387.                JZ      NEXT_PARAM              ;If yes, ignore.
  1388.                CMP     AL,";"                  ;Else, is it semi-colon?
  1389.                JZ      STORE_NUMBER            ;If yes, number delimiter.
  1390.  
  1391.                SUB     AL,"0"                  ;Else, must be number; convert
  1392.                MOV     DH,AL                   ; to binary; save in DH.
  1393.                MOV     AX,10                   ;Multiply current total by ten.
  1394.                MUL     DL
  1395.                ADD     AL,DH                   ;Add new number.
  1396.                MOV     DL,AL                   ;Save in DL.
  1397.                MOV     BP,1                    ;Flag that number mode active.
  1398.                JMP     SHORT NEXT_PARAM        ;Next parameter.
  1399.  
  1400. STORE_NUMBER:  OR      BP,BP                   ;If number mode flag not set then
  1401.                JZ      NEXT_PARAM              ;semi-colon not prefaced with no.
  1402.                MOV     AL,DL                   ;Else, store number.
  1403.                STOSB
  1404.                JMP     SHORT NEXT_NUM          ;Reset number carrying registers.
  1405.  
  1406. QUOTE_MODE:    CMP     AL,AH                   ;Is current char a string ending
  1407.                JZ      NEXT_STRING             ; quote?  If yes, exit quote mode
  1408.                STOSB                           ;Else, store char as literal.
  1409.                JMP     SHORT NEXT_PARAM
  1410.  
  1411. ;----------------------------------------------------------------------------;
  1412. ; Remove duplicate assignments if removal leaves room for new assignment.    ;
  1413. ; If no duplicate and room, add new assignment, else flush buffer to screen. ;
  1414. ;----------------------------------------------------------------------------;
  1415.  
  1416. PARSE_END:     OR      BP,BP                   ;Was last parameter a number?
  1417.                JZ      CK_LENGTH               ;If no, skip.
  1418.                MOV     AL,DL                   ;Else, store the last number.
  1419.                STOSB
  1420. CK_LENGTH:     SUB     DI,OFFSET PARSE_BUFFER - 2   ;Calculate string length
  1421.                MOV     AX,DI                        ; including word for length.
  1422.                MOV     BX,WORD PTR PARSE_BUFFER     ;BL=new first ASCII; BH=2nd.
  1423.                MOV     CX,4                         ;String length has to be at
  1424.                OR      BL,BL                  ;+least word + 2 for old = 4
  1425.                JZ      CK_LEGAL                ; for extended key reassignment.
  1426.                DEC     CX                      ;And word + 1 for old = 3
  1427. CK_LEGAL:      CMP     AX,CX                   ; for regular ASCII reassignment.
  1428.                JB      ASSIGN_FLUSH            ;If not, illegal; flush buffer.
  1429.                JNE     DOCHK                   ;+If equal then unassign.
  1430.                XOR     AX,AX                   ;+
  1431. DOCHK:         MOV     BP,BUFFER_END           ;BP to carry buffer end pointer.
  1432.                CALL    CK_MATCH                ;Is char already reassigned?
  1433.                JC      CK_ROOM                 ;If no, check room for new.
  1434.  
  1435. CK_REMOVE:     MOV     CX,DX                   ;REASSIGN_END - string end
  1436.                SUB     CX,SI                   ; = bytes to move.
  1437.                JZ      CK_ROOM                 ;If zero, last string.
  1438.                SUB     DX,[DI]                 ;Is REASSIGN_END - old string
  1439.                ADD     DX,AX                   ; + new string >
  1440.                CMP     DX,BP                   ; BUFFER_END?
  1441.                JA      ASSIGN_FLUSH            ;If yes, flush buffer to screen.
  1442.                REP     MOVSB                   ;Else, move them down in buffer.
  1443.                JMP     SHORT STORE_NEW
  1444.  
  1445. CK_ROOM:       ADD     DX,AX                   ;New string + current strings.
  1446.                CMP     DX,BP                   ;Greater than buffer size?
  1447.                JA      ASSIGN_FLUSH            ;If yes, flush new string.
  1448. STORE_NEW:     MOV     SI,OFFSET PARSE_BUFFER  ;Else, room for new string.
  1449.                TEST    AX,255                  ;+Any reassign?
  1450.                JZ      NOREASG                 ;+no reassignment
  1451.                STOSW                           ;Store string length first.
  1452.                MOV     CX,AX                   ;Adjust counter.
  1453.                DEC     CX
  1454.                DEC     CX
  1455.                REP     MOVSB                   ;Store the actual string.
  1456. NOREASG:       MOV     REASSIGN_END,DI         ;+Store new string end.
  1457.                RET
  1458.  
  1459. ASSIGN_FLUSH:  CMP     AX,2                    ;+Any key number?
  1460.                JNE     FLUSHIN                 ;+no
  1461.                MOV     AX,OFFSET REASSIGNMENT_BUFFER
  1462.                MOV     REASSIGN_END,AX         ;+flush all reassigns.
  1463.                RET                             ;+
  1464. FLUSHIN:       MOV     AL,"p"                  ;+If buffer full, flush string
  1465.                JMP     FLUSH_BUFFER            ; including ending "p" command.
  1466.  
  1467. ;------------------------------------------------------------------------------;
  1468. ; INPUT:  BL = first ASCII code to match; BH = extended if BL = 0              ;
  1469. ; OUTPUT: CY = 1 if no match found; CY = 0 if match found.                     ;
  1470. ;         DI points to string length of match; DI+2 points to start of string. ;
  1471. ;         SI = end of string; DX = REASSIGN_END; BP = BUFFER_END               ;
  1472. ;------------------------------------------------------------------------------;
  1473.  
  1474. CK_MATCH:      MOV     DX,REASSIGN_END                ;Current strings end.
  1475.                MOV     SI,OFFSET REASSIGNMENT_BUFFER  ;Point to buffer.
  1476. NEXT_MATCH:    MOV     DI,SI                          ;Current record.
  1477.                CMP     DI,DX                   ;End of strings?
  1478.                JAE     NO_MATCH                ;If yes, no match.
  1479.                MOV     CX,[DI+2]               ;CL=current first ASCII; CH=2nd
  1480.                ADD     SI,[DI]                 ;Point to next record.
  1481.                CMP     BL,CL                   ;First characters match?
  1482.                JNZ     NEXT_MATCH              ;If no, check next record.
  1483.                OR      BL,BL                   ;Extended code? ie zero.
  1484.                JNZ     MATCH                   ;If no, then match.
  1485.                CMP     BH,CH                   ;Else, check second code.
  1486.                JNZ     NEXT_MATCH              ;If not same, no match.
  1487. MATCH:         CLC                             ;Else return with CY = 0
  1488.                RET
  1489.  
  1490. NO_MATCH:      STC                             ;No match; CY = 1.
  1491.                RET
  1492.  
  1493. ;----------------------------------------------------------------------;
  1494. ; Buffer area will write over disposable data and initialization code. ;
  1495. ;----------------------------------------------------------------------;
  1496.  
  1497. ESC_BUFFER            =       $
  1498. NUMBER_BUFFER         =       ESC_BUFFER + ESC_BUFFER_SIZE
  1499. PARSE_BUFFER          =       NUMBER_BUFFER
  1500. DEVICE_STATUS_BUFFER  =       PARSE_BUFFER + ESC_BUFFER_SIZE
  1501. DEVICE_STATUS_SIZE    =       11
  1502. REASSIGNMENT_BUFFER   =       DEVICE_STATUS_BUFFER + DEVICE_STATUS_SIZE
  1503.  
  1504. ;              DISPOSABLE DATA
  1505. ;              ---------------
  1506.  
  1507. SYNTAX         LABEL   BYTE
  1508. DB      "Syntax:  ANSI [FAST | SLOW][ON | OFF][KON | KOFF][PON | POFF]"     ;^
  1509. if PCB                                           ;^
  1510. DB      "[XON | XOFF]"                           ;^
  1511. endif                                            ;^
  1512. DB      CR,LF ;:                                 ;^
  1513. DB      "              [/B nnn][/C][/Q][/U][/T][/S][/P n]",CR,LF ;. ;@      ;:
  1514. DB      "FAST     = direct screen writes; default",CR,LF                    ;:
  1515. DB      "SLOW     = screen writes via BIOS",CR,LF                           ;:
  1516. DB      "ON/OFF   = active/inactive; default is ON",CR,LF                   ;:
  1517. DB      "KON/KOFF = active/inactive reassignments; default is ON",CR,LF     ;:
  1518. DB      "PON/POFF = active/inactive NEW reassignments; default is ON",CR,LF ;:
  1519. if PCB                                           ;^
  1520. DB      "XON/XOFF = active/inactive @Xnn color codes; default is ON",CR,LF  ;^
  1521. endif                                            ;^
  1522. DB      "nnn = buffer size in bytes (0 - 60K) reserved for key reassignment; "
  1523. DB      "default 200",CR,LF
  1524. DB      "/Q  = Quiet, no output when executed",CR,LF                        ;:
  1525. DB      "/U  = Uninstall",CR,LF                                             ;:
  1526. DB      "/T  = Test if loaded",CR,LF                                        ;$
  1527. if PCB                                            ;$
  1528. DB      "/S  = Load stats from ANSICOM.SYS",CR,LF                           ;@
  1529. endif                                             ;$
  1530. DB      "/Pn = Protect n lines from scrolling at top"                       ;.
  1531. CR_LF   DB     CR,LF,LF,"$"
  1532.  
  1533. STATUS_MSG     DB      "Status: $"
  1534. BUFFER_MSG     DB      CR,LF,"Buffer size: $"
  1535. BYTES_FREE     DB      CR,LF,"Bytes free:  $"
  1536. ANSI_SYS_MSG   DB      "ANSI.SYS is installed so "
  1537. NOT_INSTALLED  DB      "ANSI.COM not installed",CR,LF,"$"
  1538. CON            DB      "CON"
  1539. CON_OFFSET     EQU     10
  1540. QUIET          DB      0                             ;| Quiet Mode
  1541. SYNTAX_FLAG    DB      0                             ;; Syntax Display Flag
  1542. TEST_FLAG      DW      0                             ;^ For report use
  1543.  
  1544. SIZE_MSG       DB      "Uninstall to change buffer size",CR,LF,LF,"$"
  1545. UNLOAD_MSG     DB      "ANSI can't be uninstalled",CR,LF
  1546.                DB      "Uninstall resident programs in reverse order",CR,LF,"$"
  1547. NOT_ENOUGH     DB      "Not enough memory",CR,LF,"$"
  1548. ALLOCATE_MSG   DB      "Memory allocation error",CR,LF,BELL,"$"
  1549. INSTALL_MSG    DB      "Installed",CR,LF,"$"
  1550. UNINSTALL_MSG  DB      "Uninstalled",CR,LF,"$"
  1551. if PCB                                            ;$
  1552. NO_FILE_MSG    DB      "ANSICOM.SYS not found",CR,LF,"$"                ;@
  1553. FILE_ERROR_MSG DB      "Error reading ANSICOM.SYS",CR,LF,"$"            ;@
  1554. FILE_NAME      DB      "ANSICOM.SYS",0                                  ;@
  1555. endif                                             ;$
  1556. alrdy_installed db      0                       ;^ Installed flag
  1557. other_seg       dw      0                       ;^ Segment of installed code
  1558. errmsg0         db      "Need DOS 2.0 or greater!$" ;^
  1559. errmsg14        db      "Error using Int 2Fh!$"     ;^
  1560.  
  1561. INITIALIZE     PROC    NEAR
  1562. ;--------------------------------------------------------------------;
  1563. ; Search memory for a copy of our code, to see if already installed. ;
  1564. ;--------------------------------------------------------------------;
  1565.  
  1566.                cld                             ;^
  1567.                mov     ah,30h                  ;^ Get DOS version
  1568.                int     21h                     ;^
  1569.                xchg    al,ah                   ;^ Swap major, minor numbers
  1570.                mov     dx,offset errmsg0       ;^ Bad DOS version
  1571.                cmp     ah,2                    ;^ Run if DOS 2.0 or greater.
  1572.                jb      jmp_msg_exit            ;^
  1573.                mov     dos_version,ax          ;^ Save version number
  1574. ;^
  1575. ;^ See if a copy is already resident in memory. If > DOS 3.0, use int 2Fh.
  1576. ;^
  1577.                mov     byte ptr [start+2],0    ;^ Initialize fingerprint
  1578.                cmp     dos_version,300h        ;^ See if DOS 3.0 or later
  1579.                jb      find_copy1              ;^ No, search the old way.
  1580.                mov     cx,16                   ;^ Try 16 different IDs.
  1581. find_copy:                                     ;^
  1582.                xor     ax,ax                   ;^
  1583.                mov     es,ax                   ;^
  1584.                mov     ah,multiplex_id         ;^ Load ID.  Use Int 2Fh to
  1585.                int     2fh                     ;^   reach installed code so
  1586.                or      al,al                   ;^   that we are compatible
  1587.                jne     find_copy0              ;^   with 386 memory managers.
  1588.                push    cs                      ;^
  1589.                pop     es                      ;^ If AL not changed, ALIAS not
  1590.                jmp     short find_copy4        ;^   installed.
  1591. find_copy0:                                    ;^
  1592.                push    cx                      ;^
  1593.                call    cmpheader               ;^ See if really Alias by
  1594.                pop     cx                      ;^   comparing file headers.
  1595.                je      find_copy3              ;^
  1596.                inc     multiplex_id            ;^ ID used by another program.
  1597.                loop    find_copy               ;^   Change and try again.
  1598.                mov     dx,offset errmsg14      ;^ All IDs taken, print error
  1599. jmp_msg_exit:  jmp     msg_exit                ;^   msg and exit.
  1600. ;
  1601. ;^ For DOS 2.x find the installed code the old fashioned way by scanning
  1602. ;^ the memory control blocks.
  1603. ;^
  1604. find_copy1:                                    ;^
  1605.                xor     bx,bx                   ;^ zero BX for start
  1606.                mov     ax,cs                   ;^ keep CS value in AX
  1607. find_copy2:                                    ;^
  1608.                inc     bx                      ;^ increment search segment value
  1609.                mov     es,bx                   ;^
  1610.                assume  es:nothing              ;^
  1611.                cmp     ax,bx                   ;^ not installed if current
  1612.                je      find_copy4              ;^   segment is found.
  1613.                call    cmpheader               ;^
  1614.                jne     find_copy2              ;^ loop back if not found
  1615. find_copy3:                                    ;^
  1616.                inc     alrdy_installed         ;^ Set installed flag
  1617. find_copy4:                                    ;^
  1618.                mov     other_seg,es            ;^ Save seg of installed code
  1619. ;^                CLD                             ;All string operations forward.
  1620. ;^                MOV     BX,OFFSET START         ;Point to start of code.
  1621. ;^                NOT     BYTE PTR [BX]           ;Change a byte so no false match.
  1622. ;^                XOR     DX,DX                   ;Start at segment zero.
  1623. ;^                MOV     AX,CS                   ;Store our segment in AX.
  1624. ;^ NEXT_PARAG:    INC     DX                      ;Next paragraph.
  1625. ;^                MOV     ES,DX
  1626. ;^                CMP     DX,AX                   ;Is it our segment?
  1627. ;^                JZ      ANNOUNCE                ;If yes, search is done.
  1628. ;^                MOV     SI,BX                   ;Else, point to our signature.
  1629. ;^                MOV     DI,BX                   ; and offset of possible match.
  1630. ;^                MOV     CX,16                   ;Check 16 bytes for match.
  1631. ;^                REP     CMPSB
  1632. ;^                JNZ     NEXT_PARAG              ;If no match, keep looking.
  1633.  
  1634. ;------------------------------------------------;
  1635.  
  1636. ANNOUNCE:                                      ;|
  1637.                MOV     SI,81H                  ;Point to command line.
  1638. NEXT_CAP:      LODSB                           ;Capitalize parameters.
  1639.                CMP     AL,CR
  1640.                JZ      PARSE
  1641.                CMP     AL,"a"
  1642.                JB      NEXT_CAP
  1643.                CMP     AL,"z"
  1644.                JA      NEXT_CAP
  1645.                AND     BYTE PTR [SI - 1],5FH
  1646.                JMP     SHORT NEXT_CAP
  1647.  
  1648. ;------------------------------------------------;
  1649.  
  1650. PARSE:         MOV     SI,81H                  ;Point to command line again.
  1651. NEXT_PARA:     XOR     AX,AX                   ;Position in status parameters.
  1652.                MOV     BX,4                    ;Status parameters each 4 bytes.
  1653. NEXT_STATUS:   MOV     DI,OFFSET PARAMETERS    ;Point to "OFF ON  SLOWFAST"
  1654.                ADD     DI,AX                   ;Point to next parameter.
  1655.                ADD     AX,BX
  1656.                CMP     AX,LAST_PARAMETER       ;:Check all 8 possible statuses
  1657.                JA      CK_SWITCHES
  1658.                PUSH    SI                      ;Save command line pointer.
  1659.                MOV     CX,2                    ;Check first two bytes for match.
  1660.                CMP     AX,20                   ;: 3 Bytes for
  1661.                JB      Len_OK                  ;:   KON | KOFF | PON | POFF
  1662.                INC     CX                   ;: ;^   XON | XOFF
  1663. Len_OK:                                        ;:
  1664.                REP     CMPSB
  1665.                POP     SI                      ;Recover command line pointer.
  1666.                JNZ     NEXT_STATUS
  1667.  
  1668.                DIV     BL                      ;If match, divide offset by four.
  1669. ;:
  1670. ;:  Next 12 lines of routine changed
  1671. ;:
  1672. ;:             MOV     CL,1                    ;Set a bit to match offset.
  1673. ;:NEXT_SHIFT:  SHL     CL,1
  1674. ;:             DEC     AL
  1675. ;:             JNZ     NEXT_SHIFT
  1676. ;:             SHR     CL,1                    ;Adjust.
  1677. ;:             MOV     AH,STATUS_MASK          ;Retrieve appropriate ON/OFF
  1678. ;:             CMP     CL,ON                   ; or FAST/SLOW mask.
  1679. ;:             JBE     ADD_STATUS
  1680. ;:             ROL     AH,1
  1681. ;:             ROL     AH,1
  1682. ;:
  1683. ;:ADD_STATUS:  AND     ES:STATUS,AH            ;Mask off old status.
  1684. ;:             OR      ES:STATUS,CL            ;Add new status.
  1685. ;:
  1686.                MOV     CL,AL                ;: ;^ place count in CL (1 - 10)
  1687.                PUSH    DX                      ;^ Save Segment
  1688.                MOV     AX,AND_MASK          ;: ;^ Retrieve appropriate ON/OFF
  1689.                                                ;: FAST|SLOW|KON|KOFF|PON|POFF
  1690.                MOV     DX,OR_MASK              ;^ XON|XOFF
  1691.                DEC     CL                   ;: ;^ Make 1 - 10 into 0 - 9
  1692.                JZ      Skip_1                  ;: In position already if zero
  1693.                SHL     DX,CL                ;: ;^ Shift bit into position
  1694. Skip_1:        SHR     CL,1                    ;: divide count by 2
  1695.                JZ      Skip_2                  ;: Nevermind
  1696.                ROL     AX,CL                ;: ;^ Shift Mask into position
  1697.                ROL     AX,CL                ;: ;^
  1698. Skip_2:                                        ;:
  1699.  
  1700.                AND     ES:STATUS,AX            ;^ Mask off old status.
  1701.                OR      ES:STATUS,DX         ;: ;^ Add new status.
  1702.                POP     DX                      ;^ get back segment
  1703.                INC     SI                      ;Bump command line pointer.
  1704.                INC     SI
  1705.  
  1706. CK_SWITCHES:   LODSB                           ;Get a byte.
  1707.                CMP     AL,CR                   ;Is it carriage return?
  1708.                JNE     QUES                    ;$
  1709.                JMP     INSTALL                 ;If yes, done here.
  1710. QUES:          CMP     AL,"?"                  ;;Request for Syntax?
  1711.                JNE     CK_SW                   ;; No -
  1712.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Yes-Show Syntax
  1713. CK_SW:         CMP     AL,"/"                  ;;Is there a switch character?
  1714.                JNE     NEXT_PARA               ;;If no, keep looking.
  1715. GOT_SWITCH:    LODSB                           ;;Else, get the switch character.
  1716.                CMP     AL,"B"                  ;Is it "B" ?
  1717.                JNZ     CK_C                    ;If no, check "C".
  1718.                CALL    CK_INSTALLED            ;Else, see if already installed.
  1719.                JZ      GET_SIZE                ;If no, get buffer request size.
  1720.                MOV     DX,OFFSET SIZE_MSG      ;Else, display error message.
  1721.                CALL    PRINT_STRING
  1722. NEXT_PARA2:    JMP     SHORT NEXT_PARA
  1723. GET_SIZE:      CALL    DECIMAL_INPUT           ;Get number parameter.
  1724.                CMP     BX,REASSIGNMENT_MAX     ;If greater than maximum, use
  1725.                JBE     STORE_BUFFER            ; maximum, else use requested
  1726.                MOV     BX,REASSIGNMENT_MAX     ; size.
  1727. STORE_BUFFER:  MOV     REASSIGNMENT_SIZE,BX
  1728.                ADD     BX,OFFSET REASSIGNMENT_BUFFER  ;Calculate end of buffer.
  1729.                MOV     BUFFER_END,BX
  1730.                JMP     NEXT_PARA               ;;Too far for direct jump
  1731.  
  1732. CK_C:          CMP     AL,"C"                  ;Is it "C" ?
  1733. if PCB                                         ;$
  1734.                JNZ     CK_S                    ;@ If not, check "S".
  1735. else                                           ;$
  1736.                JNZ     CK_P                    ;$ If not, check "P".
  1737. endif                                          ;$
  1738.                MOV     ES:REASSIGN_END,OFFSET REASSIGNMENT_BUFFER  ;Clear buffer
  1739.                JMP     NEXT_PARA               ;Else, next parmater.
  1740. if PCB                                         ;$
  1741. CK_S:          CMP     AL,"S"                  ;@ Is It "S" ?
  1742.                JNZ     CK_P                    ;. If not, check "P".
  1743.                CALL    LOAD_STATS              ;@ Yes, Load Stats
  1744.                JMP     NEXT_PARA2              ;@ Next parameter (indirect)
  1745. endif                                          ;$
  1746. CK_P:          CMP     AL,"P"                  ;. Is it "P" ?
  1747.                JNZ     CK_Q                    ;|If not, check "Q".
  1748.                CMP     BYTE PTR [SI], '*'      ;$Use current row-1?
  1749.                JNE     CK_PN                   ;$no
  1750.                PUSH    SI                      ;$Get
  1751.                CALL    GET_BIOS_DATA           ;$   current
  1752.                MOV     BL, ES:CURSOR_ROW       ;$          row
  1753.                DEC     BL                      ;$             -1
  1754.                POP     SI                      ;$
  1755.                JMP     CK_PS                   ;$
  1756. CK_PN:         CALL    DECIMAL_INPUT           ;. Get number of lines
  1757. CK_PS:         MOV     ES:START_SCROLL,BL      ;. Store the value
  1758.                JMP     NEXT_PARA2              ;. Next parameter (indirect)
  1759. CK_Q:          CMP     AL,"Q"                  ;|See if Quiet Mode
  1760.                JNE     CK_U                    ;|If not, check "U".
  1761.                NOT     QUIET                   ;|If yes turn on Quiet
  1762.                JMP     NEXT_PARA               ;Else, next parmater.
  1763. CK_U:          CMP     AL,"U"                  ;Is it "U" ?
  1764.                JE      DO_U                    ;If yes, try to uninstall.
  1765.                CMP     AL,"T"                  ;; Test if Installed
  1766.                JE      DO_U
  1767.                MOV     BYTE PTR SYNTAX_FLAG, 1 ;; Syntax Error
  1768.                JMP     NEXT_PARA               ;Else, next parmater.
  1769.  
  1770. ;------------------------------------------------;
  1771.  
  1772. INSTALL:
  1773.                MOV     DX,OFFSET SIGNATURE     ;|Display our signature.
  1774.                CALL    PRINT_STRING            ;|
  1775.                CMP     BYTE PTR SYNTAX_FLAG,0  ;;Display Syntax?
  1776.                JE      SKIP_SYNTAX             ;;No
  1777.                MOV     DX,OFFSET SYNTAX        ;|Yes, Display syntax.
  1778.                CALL    PRINT_STRING            ;|
  1779. SKIP_SYNTAX:   CALL    STATUS_REPORT          ;;|Display status.
  1780.                CALL    CK_INSTALLED            ;Check if already installed.
  1781.                JZ      CK_AVAILABLE            ;If no, see if enough memory.
  1782.                XOR     AL,AL                   ;;Else, done.
  1783. EXIT2:         JMP     EXIT                    ;Exit with ERRORLEVEL = 0.
  1784.  
  1785. DO_U:          CALL    CK_INSTALLED            ;Else, see if installed.
  1786.                MOV     DX,OFFSET NOT_INSTALLED ;If no, exit with error message.
  1787.                JZ      LILLY_PAD               ;Too far for short jump.
  1788.                CMP     AL,"T"                  ;;Was it a test
  1789.                MOV     AX, STATUS              ;$return switches as ;^
  1790.                JE      EXIT2                   ;;$Yes Too far for short jump.
  1791.                JMP     UNINSTALL               ;$Else, uninstall.
  1792.  
  1793. ;--------------------------------;
  1794. ; This is the install procedure. ;
  1795. ;--------------------------------;
  1796.  
  1797. CK_AVAILABLE:  MOV     BP,OFFSET REASSIGNMENT_BUFFER   ;TSR ends at end
  1798.                ADD     BP,REASSIGNMENT_SIZE            ; of reassignment buffer.
  1799.                ADD     BP,15                           ;Round up.
  1800.                CMP     BP,DS:[6]               ;Buffer > PSP bytes in segment?
  1801.                MOV     DX,OFFSET NOT_ENOUGH    ;If yes, exit without installing
  1802.                JBE     CK_ANSI                 ;@
  1803. LILLY_PAD:     JMP     MSG_EXIT                ;@with message
  1804. CK_ANSI:       MOV     AX,3529H                ;@Get undocumented INT 29 vector.
  1805.                INT     21H
  1806.                MOV     SI,OFFSET CON           ;Does it point to ANSI.SYS?
  1807.                MOV     DI,CON_OFFSET           ;Check by looking for "CON"
  1808.                MOV     CX,3                    ; as device name.
  1809.                REP     CMPSB
  1810.                MOV     DX,OFFSET ANSI_SYS_MSG  ;Exit with error message if
  1811.                JZ      LILLY_PAD               ;ANSI.SYS loaded.
  1812.  
  1813.                MOV     OLD_INT_29[0],BX        ;Else save old interrupt.
  1814.                MOV     OLD_INT_29[2],ES
  1815.                MOV     DX,OFFSET ANSI_INT_29   ;Install new interrupt.
  1816.                MOV     AX,2529H
  1817.                INT     21H
  1818.                MOV     AX,3516H                ;Get INT 16 vector.
  1819.                INT     21H
  1820.                MOV     OLD_INT_16[0],BX        ;Save old interrupt.
  1821.                MOV     OLD_INT_16[2],ES
  1822.                MOV     DX,OFFSET ANSI_INT_16   ;Install new interrupt.
  1823.                MOV     AX,2516H
  1824.                INT     21H
  1825.                MOV     AX,3521H                ;Get DOS 21h interrupt.
  1826.                INT     21H
  1827.                MOV     OLD_INT_21[0],BX        ;Save old interrupt.
  1828.                MOV     OLD_INT_21[2],ES
  1829.                MOV     DX,OFFSET ANSI_INT_21   ;Install new interrupt.
  1830.                MOV     AX,2521H
  1831.                INT     21H
  1832. if PCB                                            ;$
  1833.                MOV     AX,3508H                ;@ Get INT 08 vector.
  1834.                INT     21H                     ;@
  1835.                MOV     OLD_INT_08[0],BX        ;@ Save old interrupt.
  1836.                MOV     OLD_INT_08[2],ES        ;@
  1837.                MOV     DX,OFFSET ANSI_INT_08   ;@ Install new interrupt.
  1838.                MOV     AX,2508H                ;@
  1839.                INT     21H                     ;@
  1840. endif                                             ;$
  1841.                cmp     dos_version,300h        ;^ See if we are using Int 2Fh
  1842.                jb      install_3               ;^
  1843.                mov     ax,352fh                ;^ Get interrupt 2F (MUX)
  1844.                int     21h                     ;^  vector.
  1845.                mov     word ptr [int2fh],bx    ;^
  1846.                mov     word ptr [int2fh+2],es  ;^
  1847.                mov     ax,252fh                ;^ Point int 2F to internal
  1848.                mov     dx,offset muxint        ;^  routine.
  1849.                int     21h
  1850. Install_3:                                     ;^
  1851.  
  1852.                MOV     AX,DS:[2CH]             ;Get environment segment.
  1853.                MOV     ES,AX
  1854.                MOV     AH,49H                  ;Free up environment.
  1855.                INT     21H
  1856.  
  1857.                MOV     DX,OFFSET INSTALL_MSG   ;Display install message.
  1858.                CALL    PRINT_STRING
  1859.                CALL    FLUSH_END               ;Setup the number buffer.
  1860.                MOV     DX,BP                   ;Retrieve resident byte request.
  1861.                MOV     CL,4
  1862.                SHR     DX,CL                   ;Convert to paragraphs.
  1863.                MOV     AX,3100H                ;Return error code of zero.
  1864.                INT     21H                     ;Terminate but stay resident.
  1865.  
  1866. ;-------------------------------------------------------------------;
  1867. ; Exit.  Return ERRORLEVEL code 0 if successful, 1 if unsuccessful. ;
  1868. ;-------------------------------------------------------------------;
  1869.  
  1870. MSG_EXIT:      CALL    PRINT_STRING
  1871. ERROR_EXIT:    MOV     AL,1                    ;ERRORLEVEL = 1.
  1872. EXIT:          MOV     AH,4CH                  ;Terminate.
  1873.                INT     21H
  1874.  
  1875. ;^-----------------------------------------------------------------------------
  1876. ;^ CMPHEADER compares the first 16 bytes of this file with the segment
  1877. ;^           pointed to by ES.
  1878. ;^ Entry:  DS - code segment
  1879. ;^         ES - pointer to segment to compare
  1880. ;^ Exit:   ZF - 0 = segments match.
  1881. ;^-----------------------------------------------------------------------------
  1882. cmpheader      proc    near                    ;^
  1883.                mov     si,offset start+2       ;^ Search this segment for ASCII
  1884.                mov     di,si                   ;^   fingerprint.
  1885.                mov     cx,16                   ;^
  1886.                repe    cmpsb                   ;^
  1887.                ret                             ;^
  1888. cmpheader      endp                            ;^
  1889.  
  1890. ;---------------------------------------------------;
  1891. ; This subroutine uninstalls the resident ANSI.COM. ;
  1892. ;---------------------------------------------------;
  1893.  
  1894. UNINSTALL:     AND     ES:STATUS,NOT ON        ;Turn OFF ANSI, just in case
  1895.                OR      ES:STATUS,OFF           ; can't uninstall.
  1896.                MOV     CX,ES                   ;Save segment in CX.
  1897.                MOV     AX,3529H                ;Get interrupt 29h.
  1898.                INT     21H
  1899.                CMP     BX,OFFSET ANSI_INT_29   ;Has it been hooked by another?
  1900.                JNZ     UNINSTALL_ERR2          ;@If yes, exit with error message.
  1901.                MOV     BX,ES
  1902.                CMP     BX,CX                   ;Is the segment vector same?
  1903.                JNZ     UNINSTALL_ERR2          ;@If no, exit with error message.
  1904. if PCB                                         ;$
  1905.                MOV     AX,3508H                ;@Get interrupt 08h.
  1906.                INT     21H                     ;@
  1907.                CMP     BX,OFFSET ANSI_INT_08   ;@Has it been hooked by another?
  1908.                JNZ     UNINSTALL_ERR2        ;^;@If yes, exit with error message.
  1909.                MOV     BX,ES                   ;@
  1910.                CMP     BX,CX                   ;@Is the segment vector same?
  1911.                JNZ     UNINSTALL_ERR2        ;^;@If no, exit with error message.
  1912. endif                                          ;$
  1913.                MOV     AX,3516H                ;Get interrupt 16h.
  1914.                INT     21H
  1915.                CMP     BX,OFFSET ANSI_INT_16   ;Has it been hooked by another?
  1916.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  1917.                MOV     BX,ES
  1918.                CMP     BX,CX                   ;Is the segment vector same?
  1919. UNINSTALL_ERR2:JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  1920.  
  1921.                MOV     AX,3521H                ;Get interrupt 21h.
  1922.                INT     21H
  1923.                CMP     BX,OFFSET ANSI_INT_21   ;Has it been hooked by another?
  1924.                JNZ     UNINSTALL_ERR           ;If yes, exit with error message.
  1925.                MOV     BX,ES
  1926.                CMP     BX,CX                   ;Is the segment vector same?
  1927.                JNZ     UNINSTALL_ERR           ;If no, exit with error message.
  1928.  
  1929.                MOV     AH,49H                  ;Return memory to system pool.
  1930.                INT     21H
  1931.                MOV     DX,OFFSET ALLOCATE_MSG
  1932.                JC      MSG_EXIT                ;Display message if problem.
  1933.  
  1934.                lds     dx,es:[int2fh]          ;^ Get old interrupt 2F vector
  1935.                cmp     dx,-1                   ;^ See if Int used
  1936.                je      remove_1                ;^ No, skip check of Int 2F
  1937.                mov     ax,252fh                ;^ Set interrupt
  1938.                int     21h                     ;^
  1939. remove_1:                                      ;^
  1940.                MOV     DX,ES:OLD_INT_29[0]     ;Restore old INT 29.
  1941.                MOV     DS,ES:OLD_INT_29[2]
  1942.                MOV     AX,2529H
  1943.                INT     21H
  1944. if PCB                                         ;$
  1945.                MOV     DX,ES:OLD_INT_08[0]     ;@Restore old INT 08.
  1946.                MOV     DS,ES:OLD_INT_08[2]     ;@
  1947.                MOV     AX,2508H                ;@
  1948.                INT     21H                     ;@
  1949. endif                                          ;$
  1950.                MOV     DX,ES:OLD_INT_16[0]     ;Restore old INT 16.
  1951.                MOV     DS,ES:OLD_INT_16[2]
  1952.                MOV     AX,2516H
  1953.                INT     21H
  1954.                MOV     DX,ES:OLD_INT_21[0]     ;Restore old INT 21.
  1955.                MOV     DS,ES:OLD_INT_21[2]
  1956.                MOV     AX,2521H
  1957.                INT     21H
  1958.  
  1959.                PUSH    CS
  1960.                POP     DS                      ;Point to our data.
  1961.                MOV     DX,OFFSET UNINSTALL_MSG ;Display uninstall message.
  1962.                CALL    PRINT_STRING
  1963.                OR      AL,AL                   ;Exit with ERRORLEVEL = 0.
  1964.                JMP     EXIT
  1965.  
  1966. UNINSTALL_ERR: MOV     ES,CX                   ;If error, display OFF status.
  1967.                CALL    STATUS_REPORT
  1968.                MOV     DX,OFFSET UNLOAD_MSG    ;And exit with error message.
  1969.                JMP     MSG_EXIT
  1970. INITIALIZE     ENDP
  1971.  
  1972. ;--------------------------------------------------;
  1973. ; INPUT:  SI points to parameter start.            ;
  1974. ; OUTPUT: SI points to parameter end; BX = number. ;
  1975. ;--------------------------------------------------;
  1976.  
  1977. DECIMAL_INPUT  PROC    NEAR
  1978.                XOR     BX,BX                   ;Start with zero as number.
  1979. NEXT_DECIMAL:  LODSB                           ;Get a character.
  1980.                CMP     AL,CR                   ;Carriage return?
  1981.                JZ      ADJUST_DEC              ;If yes, done here.
  1982.                CMP     AL,"/"                  ;Forward slash?
  1983.                JZ      ADJUST_DEC              ;If yes, done here.
  1984.                SUB     AL,"0"                  ;ASCII to binary.
  1985.                JC      NEXT_DECIMAL            ;If not between 0 and 9, skip.
  1986.                CMP     AL,9
  1987.                JA      NEXT_DECIMAL
  1988.                CBW                             ;Convert byte to word.
  1989.                XCHG    AX,BX                   ;Swap old and new number.
  1990.                MOV     CX,10                   ;Shift to left by multiplying
  1991.                MUL     CX                      ; last entry by ten.
  1992.                JC      DECIMAL_ERROR           ;If carry, too big.
  1993.                ADD     BX,AX                   ;Add new number and store in BX.
  1994.                JNC     NEXT_DECIMAL            ;If not carry, next number.
  1995. DECIMAL_ERROR: MOV     BX,-1                   ;Else, too big; return -1.
  1996.  
  1997. ADJUST_DEC:    DEC     SI                      ;Adjust pointer.
  1998.                RET
  1999. DECIMAL_INPUT  ENDP
  2000.  
  2001. ;-------------------------------------------------------;
  2002. ; OUTPUT: ZR = 1 if not installed; ZR = 0 if installed. ;
  2003. ;-------------------------------------------------------;
  2004.  
  2005. CK_INSTALLED:  PUSH    AX                      ;;
  2006.                MOV     AX,ES
  2007.                MOV     BX,CS
  2008.                CMP     AX,BX                   ;Compare segments.
  2009.                POP     AX                      ;;
  2010.                RET
  2011.  
  2012. ;------------------------------------------------;
  2013.  
  2014. STATUS_REPORT: MOV     DX,OFFSET STATUS_MSG
  2015.                CALL    PRINT_STRING            ;Display "Status: ".
  2016.                MOV     BX,ES:STATUS            ;^ Status is now a Word
  2017.                MOV     TEST_FLAG,1             ;^ re-ran out of registers
  2018. NEXT_REPORT:   TEST    BX,TEST_FLAG            ;^ Check this status flag
  2019.                JZ      LOOP_STATUS
  2020.  
  2021.                MOV     DX,TEST_FLAG            ;^ We need a copy to play with
  2022. ;:
  2023. ;: Next 9 Lines changed
  2024. ;:
  2025. ;:             MOV     AX,-1
  2026. ;:NEXT_BIT:    INC     AX
  2027. ;:             SHR     DL,1
  2028. ;:             JNC     NEXT_BIT
  2029. ;:             SHL     AX,1
  2030. ;:             SHL     AX,1
  2031. ;:             MOV     SI,OFFSET PARAMETERS    ;Display appropriate ON or OFF,
  2032. ;:             ADD     SI,AX                   ; SLOW or FAST.
  2033. ;:             MOV     CX,4
  2034. ;:
  2035.                MOV     SI,OFFSET PARAMETERS    ;:Display appropriate ON or OFF,
  2036.                                                ;: SLOW|FAST.  KON|KOFF|PON|POFF
  2037.                MOV     CX,4                    ;:Each four characters long
  2038. NEXT_BIT:      SHR     DX,1                 ;: ;^Is this our Word?
  2039.                JC      REPORT                  ;:Yes - Print it
  2040.                ADD     SI,CX                   ;:No  - Skip over it
  2041.                JMP     NEXT_BIT                ;:test the next bit
  2042. REPORT:        LODSB
  2043.                CALL    PRINT_CHAR
  2044.                LOOP    REPORT
  2045.                MOV     AL, " "                 ;: Space words
  2046.                CALL    PRINT_CHAR              ;:
  2047.  
  2048. LOOP_STATUS:   SHL     TEST_FLAG,1             ;^
  2049.                TEST    TEST_FLAG,03FFH         ;^
  2050.                JNZ     NEXT_REPORT          ;: ;^ Check all 10 bits
  2051.                                                ;:
  2052.                MOV     DX,OFFSET BUFFER_MSG    ;Display "Buffer size: ".
  2053.                CALL    PRINT_STRING
  2054.                MOV     AX,ES:REASSIGNMENT_SIZE
  2055.                PUSH    AX
  2056.                XOR     BP,BP
  2057.                CALL    DECIMAL_OUT             ;Display the size.
  2058.                MOV     DX,OFFSET BYTES_FREE    ;Display "Bytes free: ".
  2059.                CALL    PRINT_STRING
  2060.                POP     AX
  2061.                ADD     AX,OFFSET REASSIGNMENT_BUFFER
  2062.                SUB     AX,ES:REASSIGN_END
  2063.                CALL    DECIMAL_OUT             ;Display the bytes free.
  2064.                MOV     DX,OFFSET CR_LF
  2065.                CALL    PRINT_STRING
  2066.                RET
  2067.  
  2068. ;------------------------------------------------;
  2069.  
  2070. PRINT_CHAR:    MOV     DL,AL
  2071.                MOV     AH,2                    ;Print character via DOS.
  2072.                OR      AL,AL                   ;:Skip NULLs
  2073.                JNZ     SHORT DOS_INT           ;:
  2074.                RET                             ;:
  2075.  
  2076. PRINT_STRING:  MOV     AH,9                    ;Print string via DOS.
  2077. DOS_INT:       CMP     QUIET,0                 ;|Do we suppress output
  2078.                JNE     NO_PRINT                ;|Yes
  2079.                INT     21H                     ;|No
  2080. NO_PRINT:                                      ;|
  2081.                RET
  2082. if PCB                                         ;$
  2083. LOAD_STATS:    MOV    DX,OFFSET FILE_NAME      ;@ Stat filename
  2084.                MOV    AX,3D00H                 ;@ Open File
  2085.                INT    21H                      ;@ DOS Interupt
  2086.                MOV    DX,OFFSET NO_FILE_MSG    ;@ Assume no file
  2087.                JNC    OPEN_OK                  ;@ Ok, So far
  2088. MSG_EXIT2:     JMP    MSG_EXIT                 ;@ No file found probably
  2089. OPEN_OK:       MOV    BX,AX                    ;@ This is our Handle number
  2090.                PUSH   DS                       ;@ Save DS
  2091.                PUSH   ES                       ;@ Set ES to DS
  2092.                POP    DS                       ;@
  2093.                MOV    DX, OFFSET SUB_LIST      ;@ Point to the Sub_List
  2094.                MOV    CX, SUB_LENGTH           ;@ Get the Length ot the List
  2095.                MOV    AH,3FH                   ;@ Read from Handle
  2096.                INT    21H                      ;@ DOS Interupt
  2097.                POP    DS                       ;@ Restore DS
  2098.                PUSHF                           ;@ Save results
  2099.                PUSH   AX                       ;@
  2100.                MOV    AH,3EH                   ;@ Close Handle
  2101.                INT    21H                      ;@ DOS Interupt
  2102.                POP    AX                       ;@ Restore results
  2103.                POPF                            ;@
  2104.                MOV    DX,OFFSET FILE_ERROR_MSG ;@ Assume an error occured
  2105.                JC     MSG_EXIT2                ;@ Yep, it did
  2106.                XCHG   AX,CX                    ;@ Swap Bytes Read
  2107.                JCXZ   MSG_EXIT2                ;@ Something went wrong
  2108.                CMP    AX,CX                    ;@ Did we read the full amount
  2109.                JNE    MSG_EXIT2                ;@ No
  2110.                RET                             ;@ All went well!
  2111. endif                                          ;$
  2112. _TEXT          ENDS
  2113.                END     START
  2114.